Mobile back button access through flutter - flutter

On using onWillPop the flutter app bottomScreen closes for two conditions.
On tapping outside bottom sheet.
On pressing mobile back button.
How to make first condition disable i.e. bottom sheet should only close on clicking mobile back button.

Use isDismissible property of showModalBottomSheet. It works only for outside tap.
showModalBottomSheet(
isDismissible: false,
////other
)

Related

Put widget on top of dialogue

I use one of the Packages (flutter_upayments) and it has webview_flutter in its Dependencies shown through ( showDialog ) but --> barrierDismissible: false, ( So I can't close the dialogue by clicking out or even press back button on android)
My question is is there a possibility to place a widget that appears on top of the dialoge (close button)
thanks

Flutter overlay with unclickable background

i am using overlay in flutter and if the overlay pop up i want to prevent the user from clicking the buttons behind it like this
before click
after click
try to use ignorePointer like this Ignore pointer demo
or you can use Boolean like isShow = true, when alert popup make it isShow =false

Flutter show confirmation pop up before exiting from app

I want to take confirmation from user before leaving the app, ideally when clicked on default system back navigation button and at time my navigation stack is empty.
Suppose I am on my homepage after login, and when I try to go back instead of returning me to login page it should show a pop up dialog. And based on the selection either close the app or leave it open.
wrap your home screen widget with WillPopScope widget and inside onWillPop callback write show your dialog and take action based on user's choice

How to enable back button in a screen after using Navigator.pushReplacementNamed() to replace the page in flutter?

Let's say I have two screens A and B .
I am on screen A and I use pushReplacementNamed() to get to screen B.
Now I want to go back to screen A when user swipes right (default in iOS for back button).
Screen A :
Navigator.pushReplacementNamed(context, '/B'),
Screen B :
WillPopScope(
onWillPop: () async {
Navigator.pushReplacementNamed(context, '/A');
return false;
}),
But this is not working. Back button is still disabled.
Note - I don't want to make custom back button in AppBar to achieve this. I want to use the default back button behaviour.
What I think is wrong with your code is that you're returning false from onWillPop, return false disregards the action of the back tap. Try changing that to true.
Also if you want to eventually go back to screen A from screen B it makes more sense to just use a push() on screen A and then on screen B inside onWillPop you no longer need to manually pop the route using navigator, you can just return true.
Update
In response to the your comment below, for what you want to achieve, you can normally push a route when on Home page and then on other pages you could just use pushNamedAndRemoveUntil:
Navigator.of(context).pushAndRemoveUntil("B",ModalRoute.withName('Home'));
It will push the page you want and remove everything until page Home. Since "Home" will now always be the root, you no longer need to override onWillPop and can proceed with a normal pop on back button.
Note: Page "Home" has to already be present in the stack for this to work.
If you want to push and remove everything else from the stack change:
ModelRoute.withName("Home"),
To
(Route<dynamic> route) => false,

Dialog on top of everything

Is it possible to create a Dialog in Flutter that stays on top, even if Navigator.of(context).push() is called?