0

I want to pop my bottom modal sheet when my keyboard is hidden. But currently when I press back button keyboard gets hidden but bottom modal sheet remains opened.

I tried using package flutter_keyboard_visibility to detect if the keyboard is hidden and tried to pop the bottom navigation bar. But now when do that and press outside barrier to dismiss, there are two calls to Navigator.pop(context) method. One after hiding the keyboard and another built-in pop by the bottom modal sheet.

Can anyone help me find out how to achieve this?

Thanks.

enter image description here

Hamed
  • 5,867
  • 4
  • 32
  • 56
Humble
  • 41
  • 2
  • 8

2 Answers2

0

I would do it the following way:

a) Return WillPopScope inside the Widget build method

b) As a callback for WillPopScope I will Navigator.pop(context)

You can also try the keyboard_visiblity plugin. This will provide you a callback easily.

Pushan Gupta
  • 3,697
  • 5
  • 23
  • 39
  • I already tried keyboard_visibility package, as described in question it pops context twice. I would really appreciate if you could provide code sample with WillPopScope, seems like i could not figure out how to implement it. Thanks – Humble Mar 01 '20 at 15:21
  • @BluBox Try this: https://stackoverflow.com/questions/49356664/how-to-override-the-back-button-in-flutter – Pushan Gupta Mar 01 '20 at 15:57
0

Did you try using setState(() {}); ?

it will also helps for updating the state of screen

Aamil Silawat
  • 7,735
  • 3
  • 19
  • 37