How to pop bottom modal sheet when keyboard is hidden? - flutter

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.

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.

Did you try using setState(() {}); ?
it will also helps for updating the state of screen

Related

How to use navigation inside ModalBottomSheet in Flutter?

I want to show a Webview inside a ModalBottomSheet. The behavior I want is that the back button should navigate the webview till it can go back. I was able to achieve that using WillPopScope.
But this also disables the closing of ModalBottomSheet on tapping outside it in the grey area. How can I achieve both the behaviors?

Disble keyboard on tab bar swipe flutter

I have a tab bar in my flutter app. Tab bar view has two screens with two different forms. How ever Im editing a form on 1st tab screen and when I change to the 2nd tabscreen , text field on previous screen is selected. how can i disable keyboard on swipe for tabscreen.
tabController = TabController(length: 2, vsync: this);
tabController?.addListener(() {
if(tabController!.indexIsChanging){
FocusScope.of(Get.context!).unfocus();
}
});
I have tried the above code. But i cant dispose the keyboard on swipe
Please try the below code. I wish it will solve your problem.
SystemChannels.textInput.invokeMethod('TextInput.hide');
You are doing it in the wrong way, try this simple method to hide the soft keyboard.You should wrap your whole screen in the GestureDetector method and onTap method write this code.
FocusScope.of(context).requestFocus(new FocusNode());

How to dismiss DraggableScrollableSheet in Flutter?

I try to make a pop up card when I press on a specific button and I use DraggableScrollableSheet because I want it starts minimized then the user can drag it up to maximize it.
so the question is there some way to dismiss this widget when the user press on the back screen or any other way to dismiss it?
I just call pop function inside the onTap callback function of the GestureDetector.
Navigator.pop(context);

Which function is called when a screen is opened after popping from navigation stack?

I have 2 screens - screen A and screen B. I navigate from screen A to screen B.
I want to take some particular action when I am coming BACK to screen A by popping out screen B from the navigation stack.
I know I can use didUpdateWidge but I can't figure out an efficient way of doing it.
Is using Inherited Widget the correct way here?
Navigator.push[Named] returns a Future that completes when screen B pops. So add the code you want to execute after the pop to then.
Navigator.pushNamed(context, '/someRoute').then((_) {/* do stuff here */});
Try to use WillPopScope. This widget allows to catch back button press.

ng2-bootstrap modal hides scroll bar

I am trying to implement a modal for my application. I am using ng2-bootstrap of valor-software. Whenever the modal shows, it hides the scroll bar of the webpage and the backdrop takes the whole browser area. Due to it, the content shown in the background shifts to the right. And when i close the modal the scroll bar appears and the content shifts to its original place. I do not want my content to move right and left whenever i open the modal. Is this a bug or is there a way to make it so that the scroll bar does not get hidden when the modal opens? Please kindly point me in the right direction.