[英]Dismiss keyboard on scroll?
我在应用程序中有文本字段。 当点击文本字段时,此打开键盘会自动打开。 但是当在它后面的列表(firebaseAnimatedList)上向下滚动时,键盘不会被关闭。 这不正常,并且在 iOS 上是个大问题,因为无法按后退按钮关闭。
有谁知道怎么解决?
这就是我所做的:
NotificationListener(
onNotification: (t) {
if (t is UserScrollNotification) {
FocusScope.of(context).requestFocus(FocusNode());
}
},
child: ListView.builder(
itemBuilder: (_, i) => Container(),
itemCount: items.length,
),
);
附加ScrollListener
对我不起作用,因为 Android 使用ClampingScrollPhysics
并且它只会在 ListView 项比父项长时接收滚动事件。 但是, NotificationListener
将接收所有冒泡的事件,包括UserScrollNotification
。
您可以使用 keyboardDismissBehavior。
return ListView.builder(
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
您可以将以下代码放入列表滚动侦听器中。
FocusScope.of(context).requestFocus(new FocusNode());
这是什么给你想要的效果:
NotificationListener(
onNotification: (ScrollNotification scrollInfo) {
if (scrollInfo is ScrollUpdateNotification) {
if (scrollInfo.scrollDelta >= 20.0) {
FocusScope.of(context).requestFocus(FocusNode());
}
}
},
child: new FirebaseAnimatedList ...)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.