@@ -9,6 +9,7 @@ import '../utils/edge_insets.dart';
99import '../utils/misc.dart' ;
1010import '../utils/numbers.dart' ;
1111import '../utils/text.dart' ;
12+ import '../widgets/control_inherited_notifier.dart' ;
1213import '../widgets/error.dart' ;
1314import 'control_widget.dart' ;
1415
@@ -23,9 +24,9 @@ class AlertDialogControl extends StatefulWidget {
2324}
2425
2526class _AlertDialogControlState extends State <AlertDialogControl > {
26- Widget ? _dialog;
2727 bool _open = false ;
2828 NavigatorState ? _navigatorState;
29+ String ? _error;
2930
3031 @override
3132 void didChangeDependencies () {
@@ -48,50 +49,50 @@ class _AlertDialogControlState extends State<AlertDialogControl> {
4849 }
4950
5051 Widget _createAlertDialog () {
51- var title = widget.control. get ( "title" );
52- var content = widget.control. buildWidget ( "content" );
53- var actions = widget.control. buildWidgets ( "actions" );
54- if (title == null && content == null && actions.isEmpty) {
55- return const ErrorControl (
56- " AlertDialog has nothing to display. Provide at minimum one of the following: title, content, actions" );
57- }
58-
59- return AlertDialog (
60- title : title is Control
61- ? ControlWidget (control : title)
62- : title is String
63- ? Text (title)
64- : null ,
65- titlePadding : widget.control. getPadding ( "title_padding" ) ,
66- content : content ,
67- contentPadding : widget.control.getPadding ("content_padding" ,
68- const EdgeInsets . fromLTRB ( 24.0 , 20.0 , 24.0 , 24.0 )) ! ,
69- actions : actions ,
70- actionsPadding : widget.control.getPadding ( "actions_padding" ),
71- actionsAlignment :
72- widget.control.getMainAxisAlignment ( "actions_alignment" ) ,
73- shape : widget.control. getShape ( "shape" , Theme . of (context)) ,
74- semanticLabel : widget.control.getString ( "semantics_label " ),
75- insetPadding : widget.control.getPadding ( "inset_padding" ,
76- const EdgeInsets . symmetric (horizontal : 40.0 , vertical : 24.0 )) ! ,
77- iconPadding : widget.control. getPadding ( "icon_padding" ),
78- backgroundColor : widget.control.getColor ("bgcolor " , context),
79- buttonPadding : widget.control.getPadding ( "action_button_padding" ),
80- surfaceTintColor : widget.control.getColor ( "surface_tint_color" , context ),
81- shadowColor : widget.control. getColor ( "shadow_color" , context),
82- elevation : widget.control.getDouble ( "elevation" ) ,
83- clipBehavior :
84- parseClip ( widget.control.getString ( "clip_behavior" ), Clip .none) ! ,
85- icon : widget.control.buildIconOrWidget ( "icon" ) ,
86- iconColor : widget.control. getColor ( "icon_color" , context),
87- scrollable : widget.control.getBool ( "scrollable" , false ) ! ,
88- actionsOverflowButtonSpacing :
89- widget.control. getDouble ( "actions_overflow_button_spacing" ),
90- alignment : widget.control. getAlignment ( "alignment" ),
91- contentTextStyle :
92- widget.control. getTextStyle ("content_text_style " , Theme .of (context)),
93- titleTextStyle :
94- widget.control. getTextStyle ( "title_text_style" , Theme . of (context) ),
52+ return ControlInheritedNotifier (
53+ notifier : widget.control,
54+ child : Builder (builder : (context) {
55+ ControlInheritedNotifier . of (context);
56+ var title = widget.control. get ( "title" );
57+ return AlertDialog (
58+ title : title is Control
59+ ? ControlWidget (control : title)
60+ : title is String
61+ ? Text (title)
62+ : null ,
63+ titlePadding : widget.control. getPadding ( "title_padding" ),
64+ content : widget.control. buildWidget ( "content" ),
65+ contentPadding : widget.control. getPadding ( "content_padding" ,
66+ const EdgeInsets . fromLTRB ( 24.0 , 20.0 , 24.0 , 24.0 )) ! ,
67+ actions : widget.control. buildWidgets ( "actions" ) ,
68+ actionsPadding : widget.control.getPadding ("actions_padding" ) ,
69+ actionsAlignment :
70+ widget.control. getMainAxisAlignment ( "actions_alignment" ) ,
71+ shape : widget.control.getShape ( "shape" , Theme . of (context) ),
72+ semanticLabel : widget.control. getString ( "semantics_label" ),
73+ insetPadding : widget.control.getPadding ( "inset_padding" ,
74+ const EdgeInsets . symmetric (horizontal : 40.0 , vertical : 24.0 )) ! ,
75+ iconPadding : widget.control.getPadding ( "icon_padding " ),
76+ backgroundColor : widget.control.getColor ( "bgcolor" , context) ,
77+ buttonPadding : widget.control. getPadding ( "action_button_padding" ) ,
78+ surfaceTintColor :
79+ widget.control.getColor ("surface_tint_color " , context),
80+ shadowColor : widget.control.getColor ( "shadow_color" , context ),
81+ elevation : widget.control.getDouble ( "elevation" ),
82+ clipBehavior :
83+ parseClip ( widget.control.getString ( "clip_behavior" ), Clip .none) ! ,
84+ icon : widget.control. buildIconOrWidget ( "icon" ),
85+ iconColor : widget.control.getColor ( "icon_color" , context) ,
86+ scrollable : widget.control.getBool ( "scrollable" , false ) ! ,
87+ actionsOverflowButtonSpacing :
88+ widget.control.getDouble ( "actions_overflow_button_spacing" ) ,
89+ alignment : widget.control. getAlignment ( "alignment" ),
90+ contentTextStyle : widget.control
91+ . getTextStyle ( "content_text_style" , Theme . of (context) ),
92+ titleTextStyle : widget.control
93+ . getTextStyle ("title_text_style " , Theme .of (context)),
94+ );
95+ } ),
9596 );
9697 }
9798
@@ -102,11 +103,11 @@ class _AlertDialogControlState extends State<AlertDialogControl> {
102103 var modal = widget.control.getBool ("modal" , false )! ;
103104
104105 if (open && (open != _open)) {
105- _dialog = _createAlertDialog ();
106-
107- if (_dialog is ErrorControl ) {
108- debugPrint (
109- "AlertDialog: ErrorControl, not showing dialog: ${( _dialog as ErrorControl ). message }" ) ;
106+ if (widget.control. get ( "title" ) == null &&
107+ widget.control. get ( "content" ) == null &&
108+ widget.control. children ( "actions" ).isEmpty ) {
109+ _error =
110+ "AlertDialog has nothing to display. Provide at minimum one of the following: title, content, actions." ;
110111 return ;
111112 }
112113
@@ -118,7 +119,7 @@ class _AlertDialogControlState extends State<AlertDialogControl> {
118119 barrierColor: widget.control.getColor ("barrier_color" , context),
119120 useRootNavigator: false ,
120121 context: context,
121- builder: (context) => _dialog ! ).then ((value) {
122+ builder: (context) => _createAlertDialog () ).then ((value) {
122123 debugPrint ("Dismissing AlertDialog(${widget .control .id })" );
123124 _open = false ;
124125 widget.control.updateProperties ({"open" : false });
@@ -132,7 +133,7 @@ class _AlertDialogControlState extends State<AlertDialogControl> {
132133
133134 @override
134135 Widget build (BuildContext context) {
135- return _dialog is ErrorControl ? _dialog ! : const SizedBox .shrink ();
136+ return _error != null ? ErrorControl (_error ! ) : const SizedBox .shrink ();
136137 }
137138
138139 void _closeDialog () {
@@ -142,7 +143,7 @@ class _AlertDialogControlState extends State<AlertDialogControl> {
142143 "AlertDialog(${widget .control .id }): Closing dialog managed by this widget." );
143144 _navigatorState? .pop ();
144145 _open = false ;
145- _dialog = null ;
146+ _error = null ;
146147 } else {
147148 debugPrint (
148149 "AlertDialog(${widget .control .id }): Dialog was not opened by this widget, skipping pop." );
0 commit comments