How to dismiss DraggableScrollableSheet in Flutter? - 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);

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?

How to avoid dismiss alertDialog by tapping on screen and force closing by button in Flutter

I have an alertDialog which has 2 button "STOP" and "CONTINUE" and each of them has a specific function.
I need to force the user to perform one of these function when the alertDialog pop up, and I want to avoid that user tap on screen to dismiss it.
is there a function to avoid dismissing by tapping on screen and force using the buttons?
showDialog(
barrierDismissible: false,
....
https://api.flutter.dev/flutter/widgets/ModalRoute/barrierDismissible.html

How to close Slidable automatically in 1 second?

I am using flutter_slidable and it works well, but I would like to make that when you slide a item, automatically it returns at the original position (close) after 1 second.
And only keep opened when a bool change.
Is there any option or a way to do ir programatically?
Thanks.
Please try to read the documentation, last section is talking about your need:
How can I open the Slidable programmatically?
You can open or close the Slidable programmatically by calling the open or close method of the SlidableState. The easiest way get the SlidableState from a child is to call Slidable.of(context).
The open method has an optional parameter called actionType that let you choose which action pane to open.
How can I dismiss the Slidable programmatically?
Similar to opening or closing, you can dismiss the Slidable programmatically by calling the dismiss method of the SlidableState.
If you want to use the dismiss method without allowing your user to slide to dismiss, you can set the dragDismissible parameter of the SlidableDismissal constructor to false.
You can use this with await Future.delayed(Duration(seconds: 1),(){ //open or close });

How to pop bottom modal sheet when keyboard is hidden?

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

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.