Closed escamoteur closed 5 years ago
Thanks to https://github.com/flutter/flutter/issues/13831#issuecomment-354894994
I was able to find a workaround. Creating you own widget ensures that its build method will be called on an hot reload:
Future showMessageDialog(BuildContext context, String title, String message,
[String buttonText = 'OK']) async {
await showDialog<Null>(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return new DialogTestWidget(title: title, message: message,);
});
}
class DialogTestWidget extends StatelessWidget {
final String title;
final String message;
const DialogTestWidget({
Key key, this.title, this.message,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
child: new AlertDialog(
title: new Text(title),
content: Text(message),
actions: <Widget>[
new FlatButton(
child: new Text('CANCEL'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
),
);
}
}
Still the question remain for me if the 'builder' of `showDialog' shouldn't be run on an hot reload because it will confuse a lot of people
Great! I'm closing this issue then for the reason given in https://github.com/flutter/flutter/issues/13831#issuecomment-354894994
@zoechi Please reopen it so that the team has chance to reevaluate the question if this could be improved.
@escamoteur OK I leave it to the Flutter team, but #13831 was just closed this year, so I wouldn't expect too much.
This doesn't exactly link to your problem. But I think a lot of developers don't realise that the State
class has a method called reassemble
which resolves this kind of issue.
Docs: During development, if a hot reload occurs (whether initiated from the command line flutter tool by pressing r, or from an IDE), the reassemble method is called. This provides an opportunity to reinitialize any data that was prepared in the initState method.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v
and a minimal reproduction of the issue.
While designing a dialog yesterday I had to find out that how reload doesn't work on an open Dialog or Bottomsheet.
You can see this in this screencast https://www.screencast.com/t/AmcXBEs7xaj
The App is just the automatically created one by
flutter new