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

Add Navigator with no context to Flutter #567

Closed
wants to merge 1 commit into from
Closed

Add Navigator with no context to Flutter #567

wants to merge 1 commit into from

Conversation

jonataslaw
Copy link
Contributor

@jonataslaw jonataslaw commented Nov 16, 2019

Get is a package than allow navigate on Flutter with no context to mobile Apps(very useful with BLoC, where business logic can determine which screen to display, but business logic has no context.), friendly urls to flutter_web and improve navigation performance with no rebuild of MaterialApp with each navigation (Navigator.push does this).

You've read How to contribute right ? Yes

So tell me more about your awesome contribution and add the badge to your repo after it's accepted :D

Awesome Flutter
<a href="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/Solido/awesome-flutter">
   <img alt="Awesome Flutter" src="https://img.shields.io/badge/Awesome-Flutter-blue.svg?longCache=true&style=flat-square" />
</a>

Get is a package than allow navigate on Flutter with no context to mobile Apps, friendly urls to flutter_web and improve navigation performance with no rebuild of MaterialApp with each navigation (Navigator.push does this).
Copy link
Collaborator

@jogboms jogboms left a comment

Choose a reason for hiding this comment

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

Hey @jonataslaw

I should rather drop this review on the repo itself, but, quick question, do you know what the "context" is and why it exists?

@jonataslaw
Copy link
Contributor Author

Hey @jonataslaw

I should rather drop this review on the repo itself, but, quick question, do you know what the "context" is and why it exists?

Context is used to locate Navigator.state on your route with Navigator.of(context).
In this lib a GlobalKey is used which replaces MaterialApp's GlobalKey in navigatorKey, so navigation is no longer accessible only in the widget tree through context, and is now accessible via key.currentState (instead of Navigator.state) ).
Thus it is possible to abstract the navigation outside the widgets tree, and use it in BLoC, without having to pass a context, because the currentContext located in Get.key is exactly the same as you would use in Navigator.of(context), since materialApp will use the supplied Key instead of its own.

@Solido
Copy link
Owner

Solido commented Nov 17, 2019

I won't merge now because it's too specific as for now but the subject is interesting and we'll watch if it gains more traction !

@jogboms
Copy link
Collaborator

jogboms commented Nov 18, 2019

Context is used to locate Navigator.state on your route with Navigator.of(context).
In this lib a GlobalKey is used which replaces MaterialApp's GlobalKey in navigatorKey, so navigation is no longer accessible only in the widget tree through context, and is now accessible via key.currentState (instead of Navigator.state) ).
Thus it is possible to abstract the navigation outside the widgets tree, and use it in BLoC, without having to pass a context, because the currentContext located in Get.key is exactly the same as you would use in Navigator.of(context), since materialApp will use the supplied Key instead of its own.

Thanks, i felt the need to ask so people coming into flutter would not be misled into thinking its some kind of magic that takes the Navigator away.

@jogboms jogboms added the Observation Test of time label Nov 18, 2019
@jonataslaw
Copy link
Contributor Author

In fact navigate with no context is just one of the elements. The plugin is a full navigation plugin, which adds "friendly urls" to flutter_web, and allows navigation to be transferred to bloc, but the most important is a fix in the navigation bug of Navigator.push that rebuilds all materialApp on each route.

https://www.youtube.com/watch?v=yVBqT6hg4VA&t=121s

You may not understand the comments on this video because it is in Portuguese, but you can see from the video that using Navigator.push was spent more than double the memory than using Get. There is also an unreported CPU spike in the video caused by the default route due to materialApp rebuild

@jonataslaw
Copy link
Contributor Author

Hi, get is today a complete navigation system that facilitates navigation by routes, opening modals and snackbars (with half a line of code you can do all this), without using context.
The lib is already used a lot in large scale projects because it solves a specific navigation bug in the framework, so I think that maybe it can already be merged.

@jonataslaw jonataslaw closed this Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Observation Test of time
Projects
None yet
3 participants