Flutter 中的 TextField 可编辑

TextField in flutter as Editable

final TextEditingController _namecontroller = TextEditingController(text: 'Jeya Singh');
bool isEditable = false;

Row(
  children: [
    SizedBox(
      width: width(context) * 0.8,
        child: Column(
          children: [
            TextField(
              controller: _namecontroller,
              enabled: isEditable,
              decoration: InputDecoration(
                border: const UnderlineInputBorder(
                  borderSide: BorderSide(
                    color: purple,
                  ),
                ),
                labelText: 'Name',
                labelStyle: const TextStyle(
                fontWeight: FontWeight.w600,
              ),
              suffixIcon: IconButton(
                iconSize: 16,
                onPressed: () {
                  setState(() {
                    isEditable = true;
                  });
                },
              icon: const FaIcon(FontAwesomeIcons.pen),
            ),
          ),
          style: const TextStyle(
            fontWeight: FontWeight.bold,
            color: textBlack,
          ),
        ),
      ],
    ),
  ),
],
)

它以前的某个时间工作,但突然它不工作了,我可以为 textField 设置下划线边框,但是,我无法直观地看到它在工作,

我试图创建的 Thig 是一个可编辑的 TextField,当按下 suffixIcon 时,否则它应该只是文本格式。

您还通过将 Texfield's enabled 值设置为 false.

来禁用后缀图标

Textfield 中删除 Iconbutton 并将其放在 Textfield

旁边

像这样:

Row(
  children: [
    SizedBox(
      width: width(context) * 0.8,
        child: Column(
          children: [
            TextField(
              controller: _namecontroller,
              enabled: isEditable,
              decoration: InputDecoration(
                border: const UnderlineInputBorder(
                  borderSide: BorderSide(
                    color: purple,
                  ),
                ),
                labelText: 'Name',
                labelStyle: const TextStyle(
                fontWeight: FontWeight.w600,
              ),
            
          ),
          style: const TextStyle(
            fontWeight: FontWeight.bold,
            color: textBlack,
          ),
        ),
      ],
    ),
  ),
 IconButton(
   iconSize: 16,
    onPressed: () {
       setState(() {
                    isEditable = true;
                  });
                },
              icon: const FaIcon(FontAwesomeIcons.pen),
            ),
],
)