简体   繁体   English

Flutter:TextFormField 的进入按钮执行 GestureDetector Function

[英]Flutter: TextFormField's enter button to execute GestureDetector Function

TextFormField(
  decoration: InputDecoration(
      prefixIcon: Icon(
        Icons.email_outlined,
        color: Colors.orange,
      ),
      labelText: 'email',),
  onChanged: (v) {
    _emailV = v;
  },
);

GestureDetector(
  onTap: () {},
  child: Container(
      child: Text(
    'emaaail',
  )),
);

I have these two widgets inside the Column() .我在Column()中有这两个小部件。 When a user finishes typing an email address and press done , I want the app to execute GestureDetector - onTap() function.当用户完成输入 email 地址并按done时,我希望应用程序执行GestureDetector - onTap() function。

I'd tried with the context and stuff but did not work as expected.我尝试过使用上下文和内容,但没有按预期工作。 So, I wonder if there is any thing that I can make this works?所以,我想知道是否有任何东西可以使这个工作?

You should try Inkwell() instead of GestureDetector() if you only want the ontap function to be executed;如果您只想执行 ontap function,您应该尝试 Inkwell() 而不是 GestureDetector();

Inkwell(
     onTap: () {
          //write your function
          },
      child: Container(
              child: Text(
                     'emaaail',
                     )),
              );
     )

Create a function创建 function

// depending on your needs
void onTapFunction(){
   ...
}

add the function to the onTap in the gesture part将 function 添加到手势部分的 onTap

GestureDetector(
  onTap: onTapFunction,
  child: Container(
      child: Text(
    'emaaail',
  )),
);

add the function to the onEditingComplete in the TextFormField part将 function 添加到 TextFormField 部分的 onEditingComplete

TextFormField(
  decoration: InputDecoration(
      prefixIcon: Icon(
        Icons.email_outlined,
        color: Colors.orange,
      ),
      labelText: 'email',),
  onChanged: (v) {
    _emailV = v;
  },
   onEditingComplete: onTapFunction,
          
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter:输入时提交 TextFormField - Flutter: Submit TextFormField on Enter 当在Flutter中在TextFormField中输入文本时,如何使清除按钮出现 - how to make clear button appears when text is enter in TextFormField in flutter Flutter GestureDetector 在按钮上不起作用 - Flutter GestureDetector is not working on button Flutter Button (GestureDetector) with Navigator.push function 无法按下 - Flutter Button (GestureDetector) with Navigator.push function cannot be pressed 如何将用户的 TextFormField 输入传递给 flutter 中不同 class 中的按钮 - How to pass user's TextFormField input to a button in a different class in flutter 在flutter中禁用粘贴并从textformfield中选择所有功能按钮 - Disable paste and select all function button from textformfield in flutter Flutter:在 android 模拟器中单击复选标记/输入按钮后,TextFormField 中的文本消失 - Flutter: Text diappears from TextFormField after clicking on checkmark/enter button in android emulator Flutter 集成测试:通过 label 在 TextFormField 中输入文本 - Flutter integration testing : Enter text into TextFormField by label Flutter TextFormField 未更新其值 - Flutter TextFormField not updating it's value 在flutter的TextFormField中管理事件 - Managing events in flutter's TextFormField
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM