这是我的代码,我使用的是textformfield,这是用于otp输入的,所以每当用户点击清除按钮时,我想把注意力集中在前一个文本字段上。
TextFormField(
controller: controller,
autofocus: true,
focusNode: focusNod,
validator: (String value) {
if (value.isEmpty) {
return "";
} else {
setState(() {
otp = one.text + two.text + three.text +
four.text;
print("otp : " + otp.toString());
});
return null;
}
},
onChanged: (String number) {
if (number.isNotEmpty) {
focus.requestFocus();
}
navigation();
},
keyboardType: TextInputType.number,
inputFormatters: [
FilteringTextInputFormatter.digitsOnly,
LengthLimitingTextInputFormatter(1)
],
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
helperText: '',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(color: Colors.green)),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(color: Colors.white)),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(color: Colors.white)),
focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(color: Colors.white)),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(color: Colors.white)),
),
textInputAction: action,
cursorColor: Color(0xFFFFFFFF),
),
2条答案
按热度按时间w8f9ii691#
您应该尝试添加textInputAction:文本输入操作.上一个,文本表单字段中的
58wvjzkj2#
在OTP文本字段中,只需写入此方法即可返回导航。