Flutter基于多个页面创建表单



我需要基于多个页面创建表单,验证并在完成时提交。我如何使用提供商和flutter集团包来实现这种形式?我试着使用存储创建这样的表单,但我认为这是一种糟糕的做法。有人知道吗?谢谢!

我建议您使用flow_builder(链接(插件,它将根据状态为您处理流。存储库中的示例正是您想要的。首先,您将建立一个模型,该模型将用作状态

class Profile {
const Profile({this.name, this.age, this.weight});
final String name;
final int age;
final int weight;
Profile copyWith({String name, int age, int weight}) {
return Profile(
name: name ?? this.name,
age: age ?? this.age,
weight: weight ?? this.weight,
);
}
}

然后,您可以像这样使用FlowBuilder小部件:

FlowBuilder<Profile>(
state: const Profile(),
onGeneratePages: (profile, pages) {
return [
MaterialPage(child: NameForm()),
if (profile.name != null) MaterialPage(child: AgeForm()),
];
},
);

然后您可以使用更新表单页面中的小部件

context.flow<Profile>().update((profile) => profile.copyWith(name: _name));

最新更新