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

Unable to use before having navigator in context #38

Closed
vasilich6107 opened this issue Jan 18, 2022 · 6 comments
Closed

Unable to use before having navigator in context #38

vasilich6107 opened this issue Jan 18, 2022 · 6 comments

Comments

@vasilich6107
Copy link

vasilich6107 commented Jan 18, 2022

Hi @sososdk. Thanks for your work.
I'm trying to use this lib to display no connection popup
I need to place the Flash call before having navigator in context(i'm using auto_route lib)

MaterialApp.router(
        builder: (context, child) => Connection(child: child),
      )

I cannot use custom Overlay because Flash fails by trying to call to navigator
https://github.com/sososdk/flash/blob/master/lib/flash.dart#L94

@vasilich6107
Copy link
Author

Connection component pushes custom overlay into widget tree
At this moment there is no Navigator in context
So the Flash fails with error despite all requirements to operate are satisfied

@sososdk
Copy link
Owner

sososdk commented Jan 18, 2022

Hi @vasilich6107 , you can get the context from navigatorKey.

/// Copy from: https://github.com/Milad-Akarie/auto_route_library/blob/e5ff8b91e1/auto_route/example/lib/mobile/main.dart
class _MyAppState extends State<MyApp> {
  final authService = AuthService();
  
  final navigatorKey = GlobalKey<NavigatorState>();

  late final _rootRouter = RootRouter(
      navigatorKey
      // authGuard: AuthGuard(),
      );

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      theme: ThemeData.dark(),
      routerDelegate: _rootRouter.delegate(),
      routeInformationProvider: _rootRouter.routeInfoProvider(),
      routeInformationParser: _rootRouter.defaultRouteParser(),
      builder: (_, router) {
        return ChangeNotifierProvider<AuthService>(
          create: (_) => authService,
          child: BooksDBProvider(
            child: router!,
          ),
        );
      },
    );
  }
}

@vasilich6107
Copy link
Author

This could be a possible fix.
But isn't is easier and less verbose to make small Flash code adjustments?

@sososdk
Copy link
Owner

sososdk commented Jan 18, 2022

#39 changed the meaning of 'persistent'.

When the persistent is false, we must ensure that there is an Overlay that is not rootOverlay.

@vasilich6107
Copy link
Author

actually there is still a check at line 100
I just added silencing of the error.

For now my code works, thanks for your help.
It is up to you whether to merge the PR or close it.

@vasilich6107
Copy link
Author

I'm closing this issue for now

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

2 participants