为什么我们在 TextField() 中使用“onSubmitted:”语法?
In TextField( ) why we use " onSubmitted : " syntax?
为什么在 TextField()
中使用 onSubmitted:
选项,
我想制作 Textfield 而不是 onsubmited 选项来了,我不明白最终结果有什么变化,谁能给我解释一下为什么我们使用 onSubmitted 选项?
这是我的代码:
TextField(
style: TextStyle(
color: Colors.lightBlueAccent,
),
decoration: InputDecoration(
labelText: "Password",
labelStyle: TextStyle(
color: Colors.grey,
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.grey.shade300,
width: 2,
),
borderRadius: BorderRadius.circular(30),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.blue,
width: 2,
),
borderRadius: BorderRadius.circular(30),
),
prefixIcon: Icon(
Icons.lock_outline,
),
),
),
onSubmitted
用于当您按下回车键时触发回调函数(如打印或其他函数)。
TextField(
onSubmitted: (value){
print(value);
},
),
onSubmitted
property called when the user indicates that they are done editing the text in the field.
当用户按下键盘上的Enter
并使用TextField
时,它调用onSubmitted
,它提供TextField
的value
。假设,我们没有任何 TextEditingController
或使用 onChanged
,我们可以使用 setState
方法在这里赋值。只有当我只关心最终价值时,我才喜欢它。
为什么在 TextField()
中使用 onSubmitted:
选项,
我想制作 Textfield 而不是 onsubmited 选项来了,我不明白最终结果有什么变化,谁能给我解释一下为什么我们使用 onSubmitted 选项?
这是我的代码:
TextField(
style: TextStyle(
color: Colors.lightBlueAccent,
),
decoration: InputDecoration(
labelText: "Password",
labelStyle: TextStyle(
color: Colors.grey,
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.grey.shade300,
width: 2,
),
borderRadius: BorderRadius.circular(30),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.blue,
width: 2,
),
borderRadius: BorderRadius.circular(30),
),
prefixIcon: Icon(
Icons.lock_outline,
),
),
),
onSubmitted
用于当您按下回车键时触发回调函数(如打印或其他函数)。
TextField(
onSubmitted: (value){
print(value);
},
),
onSubmitted
property called when the user indicates that they are done editing the text in the field.
当用户按下键盘上的Enter
并使用TextField
时,它调用onSubmitted
,它提供TextField
的value
。假设,我们没有任何 TextEditingController
或使用 onChanged
,我们可以使用 setState
方法在这里赋值。只有当我只关心最终价值时,我才喜欢它。