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

navigator key added #232

Closed
wants to merge 7 commits into from
Closed

navigator key added #232

wants to merge 7 commits into from

Conversation

xoltawn
Copy link

@xoltawn xoltawn commented Nov 17, 2021

It is related to this issue:
#195
I sent a pull request earlier but it has conflicts with main branch. so I send another PR regarding that issue
(sorry for the delay)

@xoltawn
Copy link
Author

xoltawn commented Nov 17, 2021

you just need to add
navigatorKey: GlobalKey<NavigatorState>(),
to your
RoutemasterDelegate;
then you can access current navigator key using:
routeMaster.navigatorKey

@anthonysette
Copy link

This would be a great feature. I was reviewing your code, why did you import lib/app.dart? @tomgilder could you review this?

My use case would be in the situation where you want to send in-app notifications. These snack bars depend on the current context and as of now, it needs to be passed around to keep it up to date with the current page. In some situations, the context is not current and so we get an error looking up a deactivated widget. If we had access to the current context for any page it would be a lot simpler to build out a notification handler. And there are plenty of other use cases such as the one @xoltawn mentioned in his last PR.

Let's get this pushed through, this is a great addition to the package.

@xoltawn
Copy link
Author

xoltawn commented Nov 19, 2021

@anthonysette importing the file must be an accident. I'm gonna remove it and push again

@anthonysette
Copy link

That would be great! We need to get a reviewer in here to close the PR. Once the fix is up I will test it, but I love this idea!

@xoltawn
Copy link
Author

xoltawn commented Nov 19, 2021

@anthonysette I just don't understand. I run flutter test on my machine and all tests pass. how should I check for more errors?

@anthonysette
Copy link

@tomgilder Can we merge this? The community would benefit a lot from this!

Copy link

@anthonysette anthonysette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested and am currently using these changes in production. This PR is solid. There have been no issues.

@xoltawn
Copy link
Author

xoltawn commented Dec 27, 2021

@tomgilder Will this be merged?

lib/routemaster.dart Outdated Show resolved Hide resolved
lib/routemaster.dart Outdated Show resolved Hide resolved
lib/routemaster.dart Outdated Show resolved Hide resolved
@xoltawn
Copy link
Author

xoltawn commented Jan 10, 2022

@BazinC changes are made to solve the issues you mentioned

@tomgilder tomgilder added this to High priority in Issue triage Mar 12, 2022
@tomgilder
Copy link
Owner

Hi @xoltawn @anthonysette I've added this a slightly different way in PR #262.

Providing a GlobalKey<NavigatorState> will give you access to the context and navigator:

final navigatorKey = GlobalKey<NavigatorState>();

final delegate = RoutemasterDelegate(
  navigatorKey: navigatorKey,
  routesBuilder: (_) => RouteMap(
    routes: {
      '/': (_) => const MaterialPageOne(),
      '/two': (_) => const MaterialPageTwo(),
    },
  ),
);

// Get the current context
final context = navigatorKey.currentContext!;

// Pop the navigator
navigatorKey.currentState!.pop();

@tomgilder tomgilder closed this Mar 13, 2022
Issue triage automation moved this from High priority to Closed Mar 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants