簡體   English   中英

如何在顫動中檢測鍵盤完成動畫

[英]How detect keyboard finish animation in flutter

在我的頁面中,我有textfield ,當點擊textfield打開鍵盤,現在我想知道何時完成鍵盤打開動畫。 當我使用任何關於鍵盤的包時,啟動動畫時鍵盤可見屬性變為真。

您可以將偵聽器添加到要觀察的類。 例如

     class KeyboardTogglePage extends StatefulWidget {
        @override
        _KeyboardTogglePageState createState() => _KeyboardTogglePageState();
      }
    
     class _KeyboardTogglePageState extends State<KeyboardTogglePage>
          with WidgetsBindingObserver {
        @override
        void initState() {
          super.initState();
          WidgetsBinding.instance.addObserver(this);
        }
    
        @override
        void dispose() {
          WidgetsBinding.instance.removeObserver(this);
          super.dispose();
        }
    
        var isKeyboardOpen = false;
    
        ///
        /// This routine is invoked when the window metrics have changed.
        ///
        @override
        void didChangeMetrics() {
          final value = MediaQuery.of(context).viewInsets.bottom;
          if (value > 0) {
            if (isKeyboardOpen) {
              _onKeyboardChanged(false);
            }
            isKeyboardOpen = false;
          } else {
            isKeyboardOpen = true;
            _onKeyboardChanged(true);
          }
        }
    
        _onKeyboardChanged(bool isVisible) {
          if (isVisible) {
            print("KEYBOARD VISIBLE");
          } else {
            print("KEYBOARD HIDDEN");
          }
        }
    
        @override
        Widget build(BuildContext context) {
          return Container(
            child: Center(
              child: TextField(),
            ),
          );
        }
      }

信用從這里。 https://stackoverflow.com/a/52140861/11612628

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM