【发布时间】:2020-06-22 03:22:21
【问题描述】:
当用户在外面点击时,尝试使用 GestureDetector 使 TextFormField 失焦,但我无法让它工作。 onTap 从不触发。
class EditScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: new GestureDetector(
onTap: () {
print('this does not fire, why???????????');
// this is my attempt to unfocus textformfield when click away
FocusScope.of(context).requestFocus(new FocusNode());
},
child: SingleChildScrollView(
child: Column(
children: <Widget>[
TextFormField(
maxLines: null,
),
],
),
),
),
);
}
}
【问题讨论】:
-
把它放在
Stack。有几个示例可以说明您尝试围绕 SO 做的事情。 -
尝试在堆栈的背景上定义一种颜色,以确保您触摸它。它可能没有按预期调整大小。