如何实现每隔几秒钟或当用户停止在TextField中键入时触发的回调?
或者只是直接在onChanged回调中实现是有效的吗?
input字段onChanged会在用户键入时提供输入值,因此您可以使用onChnaged回调函数来保存输入,如下所示,
TextFormField(
controller: _nameController,
onChanged: (value) {
saveData();
},
initialValue: widget.user.userName,
onSaved: (val) {
widget.user.userName = val;
},
validator: (val) =>
val.length > 3 ? null : 'Full name is invalid',
decoration: InputDecoration(
labelText: 'Full Name',
hintText: 'Enter your full name',
icon: Icon(Icons.person),
isDense: true,
),
),