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

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

本文介绍了文本字段无法在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.

这篇关于文本字段无法在Flutter中编辑文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 05:45