键盘成为第一响应者,TextField有默认文字时,光标没有位于最后的位置
Expanded(
child: CupertinoTextField(
controller: TextEditingController.fromValue(TextEditingValue(
text: defaultText,
// 保持光标在最后
selection: TextSelection.fromPosition(TextPosition(
affinity: TextAffinity.downstream,
offset: defaultText.length)))),
decoration: BoxDecoration(
color: Colors.grey.shade50,
border: Border.all(color: Colors.grey, width: 0.3),
borderRadius: BorderRadius.all(Radius.circular(5)),
),
onChanged: (text) {
newGroupName = text;
},
autofocus: true,
cursorColor: Colors.green,
),
),