gpt4 book ai didi

flutter - 在Flutter中输入值时如何保存TextField的值

转载 作者:IT王子 更新时间:2023-10-29 06:49:58 28 4
gpt4 key购买 nike

我在有状态类中有这段代码变量

String sth1 ;
String sth2 ;

我需要这些变量,以便在输入内容后分别从两个 TextFields 中获取一个值。这是我的

         TextField(
autofocus: true,
focusNode: f1,
inputFormatters: [
LengthLimitingTextInputFormatter(1),
],
keyboardType: TextInputType.number,
onChanged: (newVal) {
if (newVal.length == 1) {
newVal = sth1;


f1.unfocus();
FocusScope.of(context).requestFocus(f2);
}

最佳答案

您的 onChanged 应该有 sth1 = newVal 而不是 newVal = sth1

关于flutter - 在Flutter中输入值时如何保存TextField的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51917888/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com