Flutter 如何在颤振中使用作用域模型管理多页表单状态

Flutter 如何在颤振中使用作用域模型管理多页表单状态,flutter,state,scoped-model,Flutter,State,Scoped Model,我有一个多页表单,我需要用它来管理状态。我目前正在尝试使用作用域模型,但它不起作用。我转到另一页的所有内容都已清除。我通常是创建多页表单的PageView小部件。我真正知道的是为什么国家没有坚持下去。谢谢您希望确保ScopedModel正确包装多页表单中的所有页面。通常,您希望使用ScopedModel包装整个应用程序。大概是这样的: Future startUp() async { UserModel userModel = await loadUser(); runApp(Scope

我有一个多页表单,我需要用它来管理状态。我目前正在尝试使用作用域模型,但它不起作用。我转到另一页的所有内容都已清除。我通常是创建多页表单的PageView小部件。我真正知道的是为什么国家没有坚持下去。谢谢

您希望确保ScopedModel正确包装多页表单中的所有页面。通常,您希望使用ScopedModel包装整个应用程序。大概是这样的:

Future startUp() async {
  UserModel userModel = await loadUser();
  runApp(ScopedModel<UserModel>(model: userModel, child: MyApp()));
}

void main() {
  SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown,
  ]);
  startUp();
}
Future startUp()异步{
UserModel UserModel=await loadUser();
runApp(ScopedModel(model:userModel,child:MyApp());
}
void main(){
SystemChrome.setPreferredOrientations([
DeviceOrientation.Up,
DeviceOrientation.down,
]);
启动();
}
在某些情况下,您希望在模型更改时重新生成(用户登录?)
例如:

  @override
  Widget build(BuildContext context) {
    return ScopedModelDescendant<UserModel>(
        builder: (BuildContext context, Widget child, UserModel model) {
      return Scaffold(
          body: ListView(
            children: <Widget>[
              // your page here
            ]
          )
      );
    });
  }
@覆盖
小部件构建(构建上下文){
返回范围modeldescendant(
生成器:(BuildContext上下文、小部件子项、用户模型){
返回脚手架(
正文:ListView(
儿童:[
//你的页面在这里
]
)
);
});
}

您希望确保ScopedModel正确包装多页表单中的所有页面。通常,您希望使用ScopedModel包装整个应用程序。大概是这样的:

Future startUp() async {
  UserModel userModel = await loadUser();
  runApp(ScopedModel<UserModel>(model: userModel, child: MyApp()));
}

void main() {
  SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown,
  ]);
  startUp();
}
Future startUp()异步{
UserModel UserModel=await loadUser();
runApp(ScopedModel(model:userModel,child:MyApp());
}
void main(){
SystemChrome.setPreferredOrientations([
DeviceOrientation.Up,
DeviceOrientation.down,
]);
启动();
}
在某些情况下,您希望在模型更改时重新生成(用户登录?)
例如:

  @override
  Widget build(BuildContext context) {
    return ScopedModelDescendant<UserModel>(
        builder: (BuildContext context, Widget child, UserModel model) {
      return Scaffold(
          body: ListView(
            children: <Widget>[
              // your page here
            ]
          )
      );
    });
  }
@覆盖
小部件构建(构建上下文){
返回范围modeldescendant(
生成器:(BuildContext上下文、小部件子项、用户模型){
返回脚手架(
正文:ListView(
儿童:[
//你的页面在这里
]
)
);
});
}

我已经解决了这个问题,就像您在第二行调用模型时所做的那样,而不是像以前那样直接调用模型。但是我确实喜欢你添加的其他东西。我已经解决了这个问题,就像你在第二行调用模型时所做的那样,而不是像以前那样直接调用模型。不过,我确实喜欢你添加的其他内容。