这应该是自然而然的,你不应该直接关心这一点,因为实际上,当你打开键盘弹出一条路线时,它应该正确地关闭。
但是,如果您想检测用户何时开始滑动并关闭键盘,然后弹出当前路线,您可以通过使用GestureDetector
类似这样的包装屏幕小部件来轻松实现它:
Widget build(BuildContext context) {
double dragStart = 0.0;
return GestureDetector(
onHorizontalDragStart: (details) => dragStart = details.globalPosition.dx,
onHorizontalDragUpdate: (details) {
final double screenWidth = MediaQuery.of(context).size.width;
// Here I considered a back swipe only when the user swipes until half of the screen width, but you can tweak it to your needs.
if (dragStart <= screenWidth * 0.05 && details.globalPosition.dx >= screenWidth) {
FocusScope.of(context).unfocus();
}
child: // Your other widgets...
},