How to listen to keyboard on screen Flutter?

后端 未结 5 944
栀梦
栀梦 2021-01-02 08:03

I am building a mobile app, I want to remove a widget when the keyboard appears on the screen, i.e when the input text field is on focus.

I have tried to use

5条回答
  •  孤街浪徒
    2021-01-02 08:41

    You can use this library keyboard_visibility: ^0.5.6 at : https://pub.dev/packages/keyboard_visibility

    For execute your code, insert this in the initState()

    KeyboardVisibilityNotification.addNewListener( onChange: (bool visible) { print(visible); this.setState(() { keyboardIsOpen = visible; }); }, );

    Whenever keyboard is open or closed, the library calls onChange method with the visibility boolean.

提交回复
热议问题