【发布时间】:2018-11-24 10:40:32
【问题描述】:
我在 ListView 中有一个 TextFormField,我发现了一个问题,即当 TextFormField 不在屏幕上时,onsaved 回调从未调用过。我计划使用 TextEditingController 手动保存该值,但这是一个好方法吗?
这里有一些sn-p代码:
class _MyHomePageState extends State<MyHomePage> {
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Title"),
actions: <Widget>[
IconButton(
icon: Icon(Icons.save),
onPressed: () {
_formKey.currentState.save();
},
)
],
),
body: Form(
key: _formKey,
child: ListView(
children: List<int>.generate(30, (index) => index).map((v) {
return TextFormField(
decoration: InputDecoration(labelText: "Input $v"),
onSaved: (v1) => print("On save $v called"),
);
}).toList(),
),
),
);
}
}
“On save $v called”并非针对所有字段打印。
【问题讨论】:
-
你有代码要分享吗?
标签: flutter