gpt4 book ai didi

firebase - flutter 形式-多屏幕

转载 作者:行者123 更新时间:2023-12-03 04:11:20 24 4
gpt4 key购买 nike

我需要在应用程序上准备一份注册表格,而且注册表格很长,所以我如何将注册分为两个屏幕,所以当您完成第一个屏幕后,单击“下一步”按钮便会转到下一个屏幕。在下一个屏幕上,所有表单变量都应该在上一页可用。在第二页上,我想将所有变量保存到Google Firebase。

有什么建议可以实现吗?

提前致谢。

最佳答案

这是一个非常简化的示例,说明如何将TextFormFields中的数据从一个 View 传递到下一个 View :

class FirstFormPage extends StatefulWidget {
@override
_FirstFormPageState createState() => _FirstFormPageState();
}

class _FirstFormPageState extends State<FirstFormPage> {
TextEditingController _firstFormFieldController = TextEditingController();
TextEditingController _secondFormFieldController = TextEditingController();
TextEditingController _thirdFormFieldController = TextEditingController();

@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
TextFormField(
controller: _firstFormFieldController,
),
TextFormField(
controller: _secondFormFieldController,
),
TextFormField(
controller: _thirdFormFieldController,
),
RaisedButton(
child: Text('Next'),
onPressed: () => Navigator.of(context).push(MaterialPageRoute(
builder: (context) {
return SecondFormPage([
_firstFormFieldController.text,
_secondFormFieldController.text,
_thirdFormFieldController.text,
]);
}
)),
)
],
);
}
}

class SecondFormPage extends StatefulWidget {
final List<String> previousFields;

SecondFormPage(this.previousFields);

@override
_SecondFormPageState createState() => _SecondFormPageState();
}

class _SecondFormPageState extends State<SecondFormPage> {
TextEditingController _firstFormFieldController = TextEditingController();
TextEditingController _secondFormFieldController = TextEditingController();
TextEditingController _thirdFormFieldController = TextEditingController();

List<String> allData = [];

@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
TextFormField(
controller: _firstFormFieldController,
),
TextFormField(
controller: _secondFormFieldController,
),
TextFormField(
controller: _thirdFormFieldController,
),
RaisedButton(
child: Text('Next'),
onPressed: submitData,
)
],
);
}

void submitData(){
allData.addAll(widget.previousFields);
allData.addAll([
_firstFormFieldController.text,
_secondFormFieldController.text,
_thirdFormFieldController.text,
]);

// Submit your data
}
}

关于firebase - flutter 形式-多屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59706862/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com