文本字段无法在Flutter中编辑文本

问题描述:

我已经通过控制器在动态文本字段中设置了值,但是它不允许我仅在光标围绕输入的文本移动时编辑值。
我试图以此方式设置值

I have set value in dynamic textfield through the controller but it does not allow me to edit value only cursor is moving around the entered text. I have tried to set value in this way

shippingNameController.value = shippingNameController.value.copyWith(text:name);

但是在上述解决方案之前,我尝试过使用动态文本字段作为Billing name,我想更新收货名称中账单名称的值。

But before the above solution I had tried this, I'm having dynamic textfield named as Billing name and I want to update the value of billing name in the shipping name.

shippingNameController.text=name;

这在我使用时不起作用,它在文本字段的开头显示光标而不更新

this was not working when I have used this it was showing cursor at the start of textfield and not updating the value.

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;
            });
          },),

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

Have you adding listener to the controller. Add the full code.