Ad
How To Manage Multi Page Form State With Scoped Model In Flutter
I have a multi page form that I need to manage state with. I am currently trying to use the scoped model but it's not working. Everything I go to another page the state is cleared. I'm usually the PageView widget to create the multi page form. What I really what do know is why the state is not persisting. Thank you
Ad
Answer
You want to make sure your ScopedModel is correctly wrapping all of the pages in your multi page form. Often, you want to wrap your entire app with your ScopedModel. Something like this:
Future startUp() async {
UserModel userModel = await loadUser();
runApp(ScopedModel<UserModel>(model: userModel, child: MyApp()));
}
void main() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
startUp();
}
In some situations, you want to rebuild whenever the Model changes (users logs in?)
Example:
@override
Widget build(BuildContext context) {
return ScopedModelDescendant<UserModel>(
builder: (BuildContext context, Widget child, UserModel model) {
return Scaffold(
body: ListView(
children: <Widget>[
// your page here
]
)
);
});
}
Ad
source: stackoverflow.com
Related Questions
- → How do you create a 12 or 24 mnemonics code for multiple cryptocurrencies (ETH, BTC and so on..)
- → Flutter: input text field don't work properly in a simple example..... where am I wrong?
- → Can I customize the code formatting of Dart code in Atom?
- → Is it possible to develop iOS apps with Flutter on a Linux virtual machine?
- → Display SnackBar in Flutter
- → JSON ObjectMapper in Flutter
- → Material flutter app source code
- → TabBarSelection No such method error
- → How do I set the animation color of a LinearProgressIndicator?
- → Add different routes/screens to Flutter app
- → Is there a way to get the size of an existing widget?
- → How to share a file using flutter
- → Is there an easy way to find particular text built from RichText in a Flutter test?
Ad