Textfield不会在颤动中编辑文本

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

我通过控制器在动态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;
            });
          },),

enter image description here

android dart flutter
3个回答
0
投票

试试这种方式

我想如果你想设置文本,那么你必须这样做

setState((){
    shippingNameController.text = "abc";
    });

0
投票

这样的东西应该有效:

child: TextField(
    keyboardType: TextInputType.text,
    onChanged: (name) {
        setState((){
            shippingNameController.text = name;
        });
    },         
),

0
投票

您是否已将侦听器添加到控制器。添加完整代码。

© www.soinside.com 2019 - 2024. All rights reserved.