I'm trying to use the showDialog(context, builder)
to display a greeting message when the user navigates to a certain page.
I tried this by calling the showDialog
in the initState
method of a stateful widget on that page. While it does work, it appears I don't have access to the actual context.
Is there a way in Flutter to access the context
in the initState()
method?
If not, is there another way to achieve this behaviour in a better way?
@override
void initState() {
super.initState();
new Future.delayed(Duration.zero, () {
showDialog(context: context,
builder: (BuildContext context) {
return new Container(child: new Text('foo'));
});
});
}