Navigation without passing context in Flutter

Save

Hello all!! In this blog we will learn that how can we done the Navigation without passing context in Flutter.

As we all know that we need to pass context while we are navigating in our application from one screen to another.But sometime we got some context issues.So without getting frustrate from that context issue we can make a global key and use it for navigation.

Check our Flutter app development services page.

So without wasting time, let’s begin the code implementation.

#Code Implementation

For the implementation of navigation without passing context, firstly we will create a global navigation key in our main.dart file as shown in below code snippet.

After creating global navigation key, now we only need to use this key where we want to navigate on another screen.Also if we are getting some context issues while navigation we can use this key.

As it is global key we can call it in any of the file.

As shown in below code snippet we are using global navigation key for navigation.

Here we are using the navigatorKey as context and passing it in the place of context.

Not only in navigation, we can also use this key in all the context required places as it is global key.

#Conclusion

Now we are done with our implementation of Navigation in our  app without passing context.It will be very beneficial when we are facing some issues related to context and unable to navigate.

or we are getting some issues while navigating ,there we can define global navigation key and use it wherever we want to navigate.

It is also more useful as we are not using any package or dependency in our implementation.

Congratulations!!!! We have implemented Navigation without passing context in flutter.

For more interesting blogs check out here – https://mobikul.com/blog/

Thanks for reading.😇

. . .
Discuss on Helpdesk

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

css.php
Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home