检测“输入键"按下是否颤抖 [英] Detect 'enter key' press in flutter

查看:59
本文介绍了检测“输入键"按下是否颤抖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就我而言,我需要扫描条形码并获取产品详细信息.通常,条形码扫描仪设备会在扫描结束时发出enter key(keycode=13) event,但是在颤动中,Enter键与Done不同,那么如何编码才能检测到TextFormField小部件中按下的Enter键?

In my case i need to scan barcode and fetch product details. Normally barcode scanner devices emit enter key(keycode=13) event at end of scanning, But in flutter enter key is not same as Done so how can code to detect enter key pressed in my TextFormField widget?

推荐答案

TextFormField(
maxLines: null,
autovalidate: true,
   validator: (value){
             if(value.contains('\n')){
              doFun(value);
              }   
            }

)

当用户按下enter key时,在文本框中创建新行.我们对此进行确认.

When user press enter key new line create in text box. We check with that.

maxLine:null-隐藏多行

autovalidate:true-自动运行验证器乐趣

autovalidate:true -to automatically run validator fun

'\n'-换行('\ s'-空格,'\ t'-tab等.

'\n' - new line ('\s'-whitespace,'\t'-tab.. etc)

这篇关于检测“输入键"按下是否颤抖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆