Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not work in WillPopScope (onWillPop) #13

Closed
unclehking opened this issue Sep 26, 2019 · 2 comments
Closed

not work in WillPopScope (onWillPop) #13

unclehking opened this issue Sep 26, 2019 · 2 comments

Comments

@unclehking
Copy link

WillPopScope(
//
onWillPop: () async{
Toast.show("test",context);
}
)

E/flutter ( 2193): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: NoSuchMethodError: The method 'insert' was called on null.
E/flutter ( 2193): Receiver: null
E/flutter ( 2193): Tried calling: insert(Instance of 'OverlayEntry')
E/flutter ( 2193): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:50:5)
E/flutter ( 2193): #1 ToastView.createView (package:toast/toast.dart:67:18)
E/flutter ( 2193):
E/flutter ( 2193): #2 Toast.show (package:toast/toast.dart:19:15)
E/flutter ( 2193): #3 AppState.build. (package:mama_call/main.dart:145:25)
E/flutter ( 2193): #4 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:49:6)
E/flutter ( 2193): #5 AppState.build. (package:mama_call/main.dart:141:26)
E/flutter ( 2193): #6 ModalRoute.willPop (package:flutter/src/widgets/routes.dart:1083:26)
E/flutter ( 2193): #7 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:49:6)
E/flutter ( 2193): #8 ModalRoute.willPop (package:flutter/src/widgets/routes.dart:1079:38)
E/flutter ( 2193): #9 NavigatorState.maybePop (package:flutter/src/widgets/navigator.dart:2004:57)
E/flutter ( 2193): #10 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:49:6)
E/flutter ( 2193): #11 NavigatorState.maybePop (package:flutter/src/widgets/navigator.dart:2001:42)
E/flutter ( 2193): #12 _WidgetsAppState.didPopRoute (package:flutter/src/widgets/app.dart:808:28)
E/flutter ( 2193): #13 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:49:6)
E/flutter ( 2193): #14 _WidgetsAppState.didPopRoute (package:flutter/src/widgets/app.dart:803:27)
E/flutter ( 2193): #15 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.handlePopRoute (package:flutter/src/widgets/binding.dart:482:26)
E/flutter ( 2193): #16 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:49:6)
E/flutter ( 2193): #17 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.handlePopRoute (package:flutter/src/widgets/binding.dart:480:30)
E/flutter ( 2193): #18 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding._handleNavigationInvocation (package:flutter/src/widgets/binding.dart:510:16)
E/flutter ( 2193): #19 MethodChannel._handleAsMethodCall (package:flutter/src/services/platform_channel.dart:397:55)
E/flutter ( 2193): #20 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:49:6)
E/flutter ( 2193): #21 MethodChannel._handleAsMethodCall (package:flutter/src/services/platform_channel.dart:394:39)
E/flutter ( 2193): #22 MethodChannel.setMethodCallHandler. (package:flutter/src/services/platform_channel.dart:365:54)
E/flutter ( 2193): #23 _DefaultBinaryMessenger.handlePlatformMessage (package:flutter/src/services/binary_messenger.dart:110:33)
E/flutter ( 2193): #24 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:49:6)
E/flutter ( 2193): #25 _DefaultBinaryMessenger.handlePlatformMessage (package:flutter/src/services/binary_messenger.dart:101:37)
E/flutter ( 2193): #26 _invoke3. (dart:ui/hooks.dart:280:15)
E/flutter ( 2193): #27 _rootRun (dart:async/zone.dart:1124:13)
E/flutter ( 2193): #28 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter ( 2193): #29 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
E/flutter ( 2193): #30 _invoke3 (dart:ui/hooks.dart:279:10)
E/flutter ( 2193): #31 _dispatchPlatformMessage (dart:ui/hooks.dart:141:5)

@appdev
Copy link
Owner

appdev commented Nov 24, 2019

You can update to new verision.
toast: ^0.1.4

@appdev appdev closed this as completed Nov 24, 2019
@crtl
Copy link

crtl commented Mar 9, 2020

I had the same issue using WillPopScope as a direct child of MaterialApp in the same widget.
Using a Builder and its BuildContext works for me.

This doesnt work:

/* ... */
MaterialApp(
  home: WillPopScope(
    onWillPop: () => Toast.show("Test", context),
    child: Navigator(),
  )
);
/* ... */

This does:

/* ... */
MaterialApp(
  home: Builder(
    builder: (_context) {
       return WillPopScope(
         onWillPop: () => Toast.show("Test", _context),
         child: Navigator(),
       )
    }
  )
);
/* ... */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants