In flutter, we want to overlay a dialog above the widget.
We were able to display the dialog after pushing the button.
However, we want to display that dialo
some of this is ambiguous, but you can show an alert dialog in a widgets init method like this
Future showDialog() async {
WidgetsBinding.instance.addPostFrameCallback((_) async {
await showDialog(
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('Title'),
content: const Text('Content')
actions: [
FlatButton(
child: const Text('OK'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
),
);
});
}
this will wait for the first frame to be drawn before showing the dialog so you can call it from init
@override
void initState() {
super.initState();
showDialog();
}