我之前已经发布了关于这个我仍然面临的问题 哪个是将数据从有状态小部件返回到无状态小部件
我使用的小部件是 DateTimePickerFormField 小部件,我将它用作有状态小部件中的子部件
所以我查看了https://flutter.io/docs/cookbook/navigation/returning-data#complete-example
用于从小部件返回数据。但是,返回数据的小部件是无状态小部件......在我的情况下不是
所以代码如下
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Add a Reminder'),
),
body:
new Container(
padding: new EdgeInsets.all(20.0),
child: new Form(
child: new ListView(
children: <Widget>[
new TextFormField(
keyboardType: TextInputType.text,
// Use email input type for emails.
decoration: new InputDecoration(
hintText: 'Title of reminder',
),
),
dateAndTimeWidget(context),
RaisedButton(
child: Text('Save'),
onPressed: () {
Navigator.pop(context);
},
)
],
),)
,
)
,
);
}
Run Code Online (Sandbox Code Playgroud)
该小部件正在调用方法:dateAndTimeWidget,它应该返回 dateTime 有状态小部件并将输出数据保存在变量中:
dateAndTimeWidget(BuildContext context) async { …Run Code Online (Sandbox Code Playgroud)