[英]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.