In the preceding code, note that the barrierDismissible property tells whether the user can tap outside of the dialog box to close it (true) or not (false). The default value is true, but as this is a "very important question," we set it to false.
The way we close the alert is by using the Navigator.pop method, passing the color that was chosen: in this, an Alert works just like a Route.
Now we only need to call this method from the onPressed property of the "Change color" button:
onPressed: () {
_showColorDialog(context).then((Color value){
setState(() {
color = value;
});
});
This recipe showed the pattern of waiting asynchronously for data coming from an alert dialog.