File tree Expand file tree Collapse file tree 4 files changed +34
-8
lines changed
Expand file tree Collapse file tree 4 files changed +34
-8
lines changed Original file line number Diff line number Diff line change @@ -105,14 +105,22 @@ class _AlertDialogControlState extends State<AlertDialogControl> {
105105 barrierDismissible: ! modal,
106106 context: context,
107107 builder: (context) => _createAlertDialog ()).then ((value) {
108- debugPrint ("Dialog dismissed" );
108+ debugPrint ("Dialog dismissed: $_open " );
109+ bool shouldDismiss = _open;
109110 _open = false ;
110- List <Map <String , String >> props = [
111- {"i" : widget.control.id, "open" : "false" }
112- ];
113- dispatch (UpdateControlPropsAction (
114- UpdateControlPropsPayload (props: props)));
115- ws.updateControlProps (props: props);
111+
112+ if (shouldDismiss) {
113+ List <Map <String , String >> props = [
114+ {"i" : widget.control.id, "open" : "false" }
115+ ];
116+ dispatch (UpdateControlPropsAction (
117+ UpdateControlPropsPayload (props: props)));
118+ ws.updateControlProps (props: props);
119+ ws.pageEventFromWeb (
120+ eventTarget: widget.control.id,
121+ eventName: "dismiss" ,
122+ eventData: "" );
123+ }
116124 });
117125 });
118126 } else if (open != _open && _open) {
Original file line number Diff line number Diff line change @@ -842,6 +842,10 @@ Properties:
842842- actionsPadding
843843- actionsAlignment (mainAxisAlignment)
844844
845+ Events:
846+
847+ - dismiss - fires when non-modal dialog is dismissed by clicking an area outside it.
848+
845849## Banner
846850
847851Docs: https://api.flutter.dev/flutter/material/MaterialBanner-class.html
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ def __init__(
3333 actions : List [Control ] = None ,
3434 actions_padding : PaddingValue = None ,
3535 actions_alignment : MainAxisAlignment = None ,
36+ on_dismiss = None ,
3637 ):
3738
3839 Control .__init__ (
@@ -56,6 +57,7 @@ def __init__(
5657 self .actions = actions
5758 self .actions_padding = actions_padding
5859 self .actions_alignment = actions_alignment
60+ self .on_dismiss = on_dismiss
5961
6062 def _get_control_name (self ):
6163 return "alertdialog"
@@ -174,3 +176,12 @@ def actions_alignment(self):
174176 @beartype
175177 def actions_alignment (self , value : MainAxisAlignment ):
176178 self ._set_attr ("actionsAlignment" , value )
179+
180+ # on_dismiss
181+ @property
182+ def on_dismiss (self ):
183+ return self ._get_event_handler ("dismiss" )
184+
185+ @on_dismiss .setter
186+ def on_dismiss (self , handler ):
187+ self ._add_event_handler ("dismiss" , handler )
Original file line number Diff line number Diff line change @@ -18,7 +18,9 @@ def main(page: Page):
1818 page .title = "Dialog Example"
1919 page .update ()
2020
21- dlg = AlertDialog (title = Text ("Hello, you!" ))
21+ dlg = AlertDialog (
22+ title = Text ("Hello, you!" ), on_dismiss = lambda e : print ("Dialog dismissed!" )
23+ )
2224
2325 def close_dlg (e ):
2426 dlg_modal .open = False
@@ -33,6 +35,7 @@ def close_dlg(e):
3335 TextButton ("No" , on_click = close_dlg ),
3436 ],
3537 actions_alignment = "end" ,
38+ on_dismiss = lambda e : print ("Modal dialog dismissed!" ),
3639 )
3740
3841 def open_dlg (e ):
You can’t perform that action at this time.
0 commit comments