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

Global Navigator Key context is not working with toastification plugin #129

Open
ilyasarafathemvigo opened this issue Aug 26, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@ilyasarafathemvigo
Copy link

Global navigator key context is not working
toastification.show( context: globalNavigatorKey.currentContext!, title: const Text('Hello, world!'), autoCloseDuration: const Duration(seconds: 5), );

To Reproduce
Steps to reproduce the behavior:

  1. Add a global navigator key in the main.dart file
Screenshot 2024-08-26 at 3 20 38 PM
  1. Pass the navigator key to MaterialApp
Screenshot 2024-08-26 at 3 21 47 PM
  1. Call the toast using this globalKey context
Screenshot 2024-08-26 at 3 22 56 PM
  1. Check the console log
    `
    [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: 'package:toastification/src/core/toastification_overlay_state.dart': Failed assertion: line 18 pos 5: '_debugInitialized': Toastification is not initialized!
    E/flutter ( 3507): ensure your app is wrapped with a ToastificationWrapper widget
    E/flutter ( 3507): #0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
    E/flutter ( 3507): Custom Animation #1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
    E/flutter ( 3507): add custom animation posibility  #2 findToastificationOverlayState (package:toastification/src/core/toastification_overlay_state.dart:18:5)
    E/flutter ( 3507): v0.3.0 released #3 Toastification.showCustom (package:toastification/src/core/toastification.dart:136:36)
    E/flutter ( 3507): Improvements #4 Toastification.show (package:toastification/src/core/toastification.dart:264:12)
    E/flutter ( 3507): how can enable showProgressBar flag when i use toastification.showCustom() method  #5 _TestScreenState.build. (package:wsac/presentation/test_screen.dart:61:32)
    E/flutter ( 3507): Welcome to toastification Discussions! #6 _InkResponseState.handleTap (package:flutter/src/material/ink_well.dart:1154:21)
    E/flutter ( 3507): Addition of dismiss all toasts at once. #7 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:275:24)
    E/flutter ( 3507): add new structure for built in toasts #8 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:654:11)
    E/flutter ( 3507): add dismissAll function #9 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:311:5)
    E/flutter ( 3507): add toastification manager and alignment to toasts #10 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:244:7)
    E/flutter ( 3507): add document for core classes #11 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:630:9)
    E/flutter ( 3507): add swipe to dismiss feature #12 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:98:12)
    E/flutter ( 3507): خطا در موقع بسته شدن دیالوگ #13 PointerRouter._dispatchEventToRoutes. (package:flutter/src/gestures/pointer_router.dart:143:9)
    E/flutter ( 3507): update and deploy example app #14 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:625:13)
    E/flutter ( 3507): fix some detected issues . #15 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:141:18)
    E/flutter ( 3507): update shadow structure & animation builder #16 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:127:7)
    E/flutter ( 3507): update default icons and primary colors #17 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:488:19)
    E/flutter ( 3507): add support for textDirection  #18 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:468:22)
    E/flutter ( 3507): add progress bar  #19 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:333:11)
    E/flutter ( 3507): add different close types #20 GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:413:7)
    E/flutter ( 3507): add custom animation to example #21 GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:376:5)
    E/flutter ( 3507): fix example design issues in v1.0.0 #22 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:323:7)
    E/flutter ( 3507): Refactor built in widget and remove opacity force change #23 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:292:9)
    E/flutter ( 3507): Add early return and delete .toList when we don't need it! #24 _invoke1 (dart:ui/hooks.dart:186:13)
    E/flutter ( 3507): Add equatable and change cupertino with widgets #25 PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:424:7)
    E/flutter ( 3507): Add _disposeAnimation() #26 _dispatchPointerDataPacket (dart:ui/hooks.dart:119:31)
    E/flutter ( 3507):

`

Expected behavior
Should display a toast without any error

Flutter information:

  • OS: android and iOS
  • Flutter Version: 3.24.0
  • Toastification Version 2.0.0

NB: All the widgets are working fine with global navigator key

@ilyasarafathemvigo ilyasarafathemvigo added the bug Something isn't working label Aug 26, 2024
@komakur
Copy link

komakur commented Sep 10, 2024

Same issue. I've been using injectable for my AppRouter and getting context like this
final context = getIt<AppRouter>().navigatorKey.currentContext!;

context is not null, and the error is the same as mentioned above

PS: for me issue happens on Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants
@komakur @ilyasarafathemvigo and others