Flutter: Popandpushnamed With Arguments Passing To New Page?
I am writing an application on Flutter. I need to do popAndPushNamed but I also need to pass arguments to the Page I am pushing. How can I do? Is there another way to pop and push
Solution 1:
For sending data to widget you can use it's constructor
String result = awaitNavigator.of(context).push(MaterialPageRoute(builder: (context) =>SecondWidget("String")));
In this case result
is new string, which will be returned from SecondWidget
classSecondWidgetextendsStatefulWidget {
SecondWidget(this.text);
final String text;
And somewhere in SecondWidgetState
:
Navigator.pop(context, "New string");
This will close SecondWidget
and return value for result
I think it's clear enough and it'll help
UPD How to do in your case (something like this)
Profile profile = awaitNavigator.of(context).push(MaterialPageRoute(builder: (context) =>LoginWidget()));
if (profile != null) Navigator.of(context).push(MaterialPageRoute(builder: (context) =>MainWidget(profile)));
In LoginWidget
:
void_afterLogIn() {
// do somethingNavigator.pop(context, this.receivedProfile);
}
In MainWidget
:
classMainWidgetextendsStatefulWidget {
MainWidget(this.profile);
Profile profile;
Post a Comment for "Flutter: Popandpushnamed With Arguments Passing To New Page?"