如何解决检测任何聚焦的文本字段颤动
现在我有一个带有 FocusScope 的文本字段列表,因为我希望文本字段仅在文本字段失焦时生效,下面是文本字段的示例
FocusScope(
child: Focus(
focusNode: node,onFocusChange: (focus) {
if (!focus) {
if (widget.controllers[3].text.isNotEmpty) {
widget.bloc.add(
// bloc function
),);
}
}
},child: TextField(
inputFormatters: [
LengthLimitingTextInputFormatter(30),FilteringTextInputFormatter.allow(
RegExp('[a-zA-Z0-9]')),],textCapitalization: TextCapitalization.characters,hintText: '',title: '',editingController: widget.controllers[3],),)
在页面底部,会有继续下一页的按钮,但是在单击按钮后,我希望应用程序先取消对每个文本字段的关注,然后再继续执行按钮 onclick 功能,我该怎么做?也许像一个函数,它可以检测是否有任何焦点放在文本字段上
FlatButton(
padding: const EdgeInsets.symmetric(
vertical: 12.0,horizontal: 20.0),shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),onpressed: (){
_unfocus(context,state);
}
child: Text(
'Continue',style: medium(
16,)
对焦功能
void _unfocus(
BuildContext context,State state,) {
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
} else {
// go to next page function ()
}
}
解决方法
您可以使用此方法unfocus
在您的onPressed
void _unfocus() {
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。