Flutter:输入文本后自动清除Textfield
我在使用提供程序的 flutter 应用程序中有这个文本字段,如下所示:
getPhoneNumberScreen(size, context) {
var remianheight = size.height - 70;
TextEditingController _phoneNumber = TextEditingController();
TextEditingController _code = TextEditingController();
return TextField(
keyboardType: TextInputType.number,
controller:
!authProvider.isPhoneNumberInserted ? _phoneNumber : _code,
decoration: InputDecoration(
isDense: true,
hintText: !authProvider.isPhoneNumberInserted
? 'Phone Number'
: 'Verification Code',
enabledBorder: UnderlineInputBorder(
borderSide: const BorderSide(
color: Color(0x00000000),
width: 1,
),
borderRadius: BorderRadius.circular(30),
),
focusedBorder: UnderlineInputBorder(
borderSide: const BorderSide(
color: Color(0x00000000),
width: 1,
),
borderRadius: BorderRadius.circular(30),
),
filled: true,
fillColor: ColorManager.helibi,
contentPadding:
const EdgeInsetsDirectional.fromSTEB(20, 15, 0, 15),
prefixIcon: const Icon(
Icons.phone_sharp,
color: Color(0xFF8F8F8F),
)),
);
}
当我尝试输入一些文本时,完成后很清楚。 还有如何使文本字段向上移动以显示。
I have this text field in flutter app using provider as shown :
getPhoneNumberScreen(size, context) {
var remianheight = size.height - 70;
TextEditingController _phoneNumber = TextEditingController();
TextEditingController _code = TextEditingController();
return TextField(
keyboardType: TextInputType.number,
controller:
!authProvider.isPhoneNumberInserted ? _phoneNumber : _code,
decoration: InputDecoration(
isDense: true,
hintText: !authProvider.isPhoneNumberInserted
? 'Phone Number'
: 'Verification Code',
enabledBorder: UnderlineInputBorder(
borderSide: const BorderSide(
color: Color(0x00000000),
width: 1,
),
borderRadius: BorderRadius.circular(30),
),
focusedBorder: UnderlineInputBorder(
borderSide: const BorderSide(
color: Color(0x00000000),
width: 1,
),
borderRadius: BorderRadius.circular(30),
),
filled: true,
fillColor: ColorManager.helibi,
contentPadding:
const EdgeInsetsDirectional.fromSTEB(20, 15, 0, 15),
prefixIcon: const Icon(
Icons.phone_sharp,
color: Color(0xFF8F8F8F),
)),
);
}
When I try to input some text, it is clear after I finish.
Also how make the textfild move up to be shown.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我从你的问题中了解到,你想在完成后清除你的 TextField,并且你想专注于你的 TextField:
对于第一个问题:你可以简单地为此创建 TextEditingController。
TextEditingController 电话控制器 = new TextEditingController();
将此控制器分配到您的 TextField 中:
在完成函数上只需调用 :
或尝试在您的提供程序中实现它。
要请求 TextField 的焦点,您必须为此实现 FocusNode。
焦点节点phoneFocusNode = new FocusNode();
在您的 TextField 中实现它:
通过调用以下命令将请求焦点放在您想要的位置:
As i understand from your question you want to clear you TextField after your finish and also you want to focus into your TextField:
For the first question: you can simply create TextEditingController for that.
TextEditingController phoneController = new TextEditingController();
Assign this controller into your TextField:
And on the finish function just call :
Or try to implement that inside your provider.
For requesting focus for the TextField, you have to implement FocusNode for that.
FocusNode phoneFocusNode = new FocusNode();
implement it inside your TextField:
the request focus where ever you want by calling:
错误是文本字段的控制器必须在方法之外:
the mistake is it controller of textfield mus be outside the method :