flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
165.01k stars 27.19k forks source link

Conditional dismissible AlertDialog #113062

Open erf opened 1 year ago

erf commented 1 year ago

Use case

I would like to make a AlertDialog dismissible determined conditionally by the state of the data in a TextField. E.g. if the user have written some text, i don't want him to accidentally press outside the dialog and dismiss it without saving changes, but if he's only having a peek at some content, he should be able to dismiss it by pressing outside. Right now you can only set barrierDismissible on showDialog as a boolean when showing it.

Proposal

I would like some way to make the dialog dismissible based on some state in the AlertDialog. Perhaps pass a DismissibleController to showDialog which i can also pass to the Dialog and update as needed. E.g. the dialog can set dismissible true or false based on e.g. the state of a TextField.

justinmc commented 1 year ago

I wonder if OverlayPortal would help with this? Like if alert dialogs were done with OverlayPortal instead of showDialog, then would we be able to rebuild them when their parameters changed like a normal widget? CC @LongCatIsLooong