Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 1050 Vote(s) - 3.51 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to check whether Alert Dialog is open in flutter

#1
I am working on my flutter application and I want to check whether the alert dialog is open or not on the screen .
Can anyone tell me how to do that, basically I want to do some stuff just before and after alert dialog opens and closes.
Reply

#2
In your case its better to use a full screen dialog then u can create frosted glass effect and in center u can add alert box like container and decorate it. To make modal barier like effect wrap outter frosted glass container with inkWell or gesture detector and on tap pop the screen
Reply

#3
You can assign the alert dialog to a variable and use the build method to populate it. Later check the variable to know whether the dialog is being shown or not.
Reply

#4
First thing is you will be showing dialog yourself. So, you can use a `bool` value to track it.

Like this.

bool _isDialogShowing = false;

void _showDialog() {
_isDialogShowing = true; // set it `true` since dialog is being displayed
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text("Title"),
actions: <Widget>[
FlatButton(
child: Text("CANCEL"),
onPressed: () {
_isDialogShowing = false; // set it `false` since dialog is closed
Navigator.of(context).pop();
},
)
],
);
},
);
}


To listen for back button, you can wrap your root widget in `WillPopScope` and handle things in `onWillPop()` accordingly.

Reply

#5
try this !!!


Future _dialog;

_checkAndShowDialog() async {

if (_dialog == null) {
_dialog = showMyDialog();
await _dialog;
_dialog = null;
} else {
//do nothing
}

}

//dialog should return future
Future showMyDialog() {
return showDialog(
context: _context,
child: Container(child: Text("I am dialog"),) );
}

Reply

#6
I had the same problem. Maybe my solution would do any better for someone:

_isOpen = true;
showDialog(
context: context,
child: AlertDialog(
title: Text("Some title!"),
content: Text("Some content!"),
)).then((_) => _isOpen = false);

The `then` will run when the alert closes.
Reply

#7
"so I want to add a frosted glass background behind my alert , so what i want to do is before pushing alert dialog i want to change my screen to frosted glass bg and then after poping up alert i want to remove that bg using setState .That's why I want to listen to the alert dialog. Hope this all makes sense to you! Thanks !"

This is what you responded as the purpose of your dialog.

You can await a dialog like this:

```
<do setup code here>

await showDialog(...);

<do final code here>

```

Regardless of how you show the dialog I don't see a flaw on this. If you don't have this on an `async` function you can always call `.then` and do stuff there:

```
<do setup code here>

showDialog(...).then((_) => <do final code here>);

```


Reply

#8
you can use this method:

_isThereCurrentDialogShowing(BuildContext context) =>
ModalRoute.of(context)?.isCurrent != true;
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through