【发布时间】:2021-08-15 05:57:10
【问题描述】:
我有选民 id api,我想显示从文本字段输入的显示特定选民详细信息,例如,如果用户输入文本字段选民姓名和选民在下一页特定选民详细信息中显示所有详细信息
【问题讨论】:
-
请在您的问题中添加更多详细信息并阅读此stackoverflow.com/help/how-to-ask
我有选民 id api,我想显示从文本字段输入的显示特定选民详细信息,例如,如果用户输入文本字段选民姓名和选民在下一页特定选民详细信息中显示所有详细信息
【问题讨论】:
1. 创建一个TextEditController,这是一个可以链接到输入字段以获取其中文本的类(最好将其放在StatefulWidget中,这样我们可以处理它):
// Define a custom Form widget.
class MyCustomForm extends StatefulWidget {
const MyCustomForm({Key? key}) : super(key: key);
@override
_MyCustomFormState createState() => _MyCustomFormState();
}
// Define a corresponding State class.
// This class holds the data related to the Form.
class _MyCustomFormState extends State<MyCustomForm> {
// Create a text controller and use it to retrieve the current value
// of the TextField.
final myController = TextEditingController();
@override
void dispose() {
// Clean up the controller when the widget is disposed.
myController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
// Fill this out in the next step.
}
}
2. 将控制器与您的文本字段链接:
TextField(
controller: myController,
);
3. 获取文本:
myController.text
4. 实现 Navigator 类,按照官方文档发送数据作为下一页的参数:
【讨论】: