如何像在桌面上的主要思想中一样,在颤振文本字段中实现自动保存?

问题描述 投票:0回答:1

如何实现每隔几秒钟或当用户停止在TextField中键入时触发的回调?

或者只是直接在onChanged回调中实现是有效的吗?

android flutter
1个回答
0
投票

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,
                ),
              ),
© www.soinside.com 2019 - 2024. All rights reserved.