zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

Flutter TextField设置默认值默认值和光标位置

flutter 设置 位置 默认值 光标 TextField
2023-09-14 09:04:26 时间

原文地址

TextField(
          //输入键盘类型
              keyboardType: TextInputType.text,
              autofocus: true,
              decoration: InputDecoration(
                border: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(),
                    borderSide: BorderSide.none),
              ),
              onChanged: (value) {
                this._keyword = value;
              },
              controller: TextEditingController.fromValue(TextEditingValue(
                  text: '${this._keyword == null ? "" : this._keyword}',  //判断keyword是否为空
                  // 保持光标在最后
 
                  selection: TextSelection.fromPosition(TextPosition(
                      affinity: TextAffinity.downstream,
                      offset: '${this._keyword}'.length)))),
            ),