This is problably sthg simple, I would like to pop a widget and to pass different parameters, here is what I have :
class MyScreen extends StatefulWidget {
final String param0;
final String param1;
final String param2;
MyScreen(param0,param1,param2);
@override
MyState createState() => new MyScreenState();
}
...
I would like to go back to this widget passing parameters, something like this :
Navigator.pop(context, "NewParam0", "NewParam1", "NewParam2");
but it doesn't work.
I can pop with 1 parameter and the context, but it doesn't work with multiple parameters,
Any idea?
Yep, the solution is simple! The way I've dealt with this is by popping an object. For instance, a Map<String, String>
:
Navigator.pop(context,
{"NewParam0": "param0value", "NewParam1": "param1value", "NewParam2": "param2value"}
);
(see https://api.flutter.dev/flutter/widgets/Navigator/pop.html and https://flutter.dev/docs/cookbook/navigation/returning-data)
You could also make a lightweight class to pop that will populate default params, etc. if you have a lot of complexity to pass back and forth, though at that point, I might try to rework my state management a little bit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With