how to passing/pushing data from Navigator.of(context).pop() and get in another page

2,641 views
Skip to first unread message

Michael Tawiah Sowah

unread,
Sep 10, 2017, 3:41:02 PM9/10/17
to Flutter Dev
can anyone help me out in how to passing/pushing data from Navigator.of(context).pop() and get in the other state?

Ian Hickson

unread,
Sep 10, 2017, 8:02:58 PM9/10/17
to Michael Tawiah Sowah, Flutter Dev
On Sun, Sep 10, 2017 at 12:41 PM Michael Tawiah Sowah <michael...@gmail.com> wrote:
How do I pass and get data value between routes in flutter 
can anyone help me out in how to passing/pushing data from Navigator.of(context).pop() and get in the other state?

It's hard to answer this without a clearer picture of what you're trying to do. As a general rule, though, routes are all "just code" and so they can all see the same data model objects that you may have in your application. Also when you call Navigator.pop(foo) the argument becomes the value of the Future that was returned when you pushed the route in the first place.

Does that help?

--

--
Ian Hickson

😸

Michael Tawiah Sowah

unread,
Sep 11, 2017, 2:14:29 AM9/11/17
to Flutter Dev
Hi Ian, thanks for the response, you guys are just awesome (Flutter dev team) and the product is really Awesome.
Let me clarify what am doing.

I have a widget/Page that request users to enter their country code and when they tap on it I load another page with the country code list that they can select from. So when the select the the country code, I want to leave the country code page, come back to the previous page and fill and input filed with their selection this page. (like  Firebase Phone Authentication, you can either enter your country code or select from a list and then after selection). Basically What I want to do is Firebase Phone Authentication but since its not available yet and I really need it for out app which is a production app. I decided to see if I could implement it myself. And yes I thought about a Firebase Phone Authentication plugin was hitting a blocks here and there so I paused and started considering the possibility of another alternative. 
But would not mind jumping back at the plugin with some help....

Michael Tawiah Sowah

unread,
Sep 11, 2017, 2:56:43 AM9/11/17
to Flutter Dev
But Ian I will still like to know how to get that data from the selection they make on the country code page.
Message has been deleted

Si...@prayuta.com

unread,
Sep 11, 2017, 7:33:16 AM9/11/17
to Flutter Dev
you can simply store the value in shared preference

by importing the plugin shared_preferences: 0.2.5

Collin Jackson

unread,
Sep 11, 2017, 3:35:59 PM9/11/17
to Michael Tawiah Sowah, Flutter Dev
In an async method that pushes the country code selection dialog onto the navigation stack, you should await the result of Navigator.push(context, ...);

(If you're using Navigator instead of showDialog, you may want to specify your route is a full-screen dialog; use the fullscreenDialog property)

In the pushed route, you should pass the result (country code) as an argument to Navigator.pop. The Future returned by Navigator.push will complete with the country code value, allowing you to fill in the selection on the previous page.

If you do implement Firebase phone auth, consider submitting a pull request to https://github.com/flutter/plugins. Thanks!

--
You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Tawiah Sowah

unread,
Sep 11, 2017, 5:31:05 PM9/11/17
to Flutter Dev
Thanks Collin.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages