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