我通过控制器在动态textfield
中设置了值,但它不允许我编辑值,只有光标在输入的文本周围移动。我试图以这种方式设定价值
shippingNameController.value = shippingNameController.value.copyWith(text:name);
但在上述解决方案之前,我尝试了这个,我的动态文本字段名为Billing名称,我想在发货名称中更新结算名称的值。
shippingNameController.text=name;
当我使用它时它不起作用它在文本字段的开头显示光标而不更新值。
new TextField(
style: TextStyle(fontFamily: 'semibold',color: MyColors.colorPrimary),
keyboardType:field.type=='STR'||field.type=='EMAIL'? TextInputType.text:TextInputType.number,
textInputAction: TextInputAction.done,
decoration: InputDecoration(contentPadding:EdgeInsets.all(8.0),
hintStyle: TextStyle(fontFamily: 'semibold',color: MyColors.colorPrimary),
border: InputBorder.none,),
controller: shippingNameController,
onChanged: (String val) {
enteredValue(field,val);
setState(() {
shippingNameController.text = val;
sShppingfieldList[p].fieldvalue=val;
});
},),
试试这种方式
我想如果你想设置文本,那么你必须这样做
setState((){
shippingNameController.text = "abc";
});
这样的东西应该有效:
child: TextField(
keyboardType: TextInputType.text,
onChanged: (name) {
setState((){
shippingNameController.text = name;
});
},
),
您是否已将侦听器添加到控制器。添加完整代码。