简体   繁体   中英

Textfield not editing text in 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);

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

在此处输入图像描述

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

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

在此处输入图片说明

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

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

在此处输入图片说明

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

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

在此处输入图片说明

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

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

在此处输入图片说明

Use controller with text

final TextEditingController _email = TextEditingController(text: '');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM