@@ -8,6 +8,16 @@ part 'confirm_action.g.dart';
88
99/// Asks the user to confirm, e.g. "Leave album?", then runs [actions] when
1010/// they confirm and [cancelActions] when they cancel or dismiss the dialog.
11+ ///
12+ /// By default the dialog is built by the runtime and takes the app's look:
13+ /// its font, primary color and surface come from the layout that shows it.
14+ /// The optional color and radius fields override that look.
15+ ///
16+ /// With a [dialogId] the dialog is that canvas instead, like
17+ /// [ShowDialogAction] . A button in it answers the dialog with a "Navigate
18+ /// back" action whose params hold [resultKey] : `true` confirms, anything else
19+ /// cancels. Closing the dialog any other way cancels. The params popped with a
20+ /// confirm are the `${result}` the [actions] read.
1121@JsonSerializable ()
1222class ConfirmAction extends ActionModel with Equatable , SerializableMixin {
1323 /// The dialog's title. Supports variables and formulas.
@@ -32,6 +42,54 @@ class ConfirmAction extends ActionModel with Equatable, SerializableMixin {
3242 /// Actions to run, in order, when the user cancels.
3343 final List <ActionModel > cancelActions;
3444
45+ /// Id of a canvas to show as the dialog instead of the built-in one, or
46+ /// null for the built-in dialog.
47+ final String ? dialogId;
48+
49+ /// Parameters passed to the [dialogId] canvas, like
50+ /// [ShowDialogAction.params] .
51+ final Map <String , dynamic > params;
52+
53+ /// Whether tapping outside the dialog dismisses it, which cancels.
54+ final bool barrierDismissible;
55+
56+ /// Color of the barrier behind the dialog. Null uses the platform's
57+ /// default scrim.
58+ final ColorRGBA ? barrierColor;
59+
60+ /// Background of the built-in dialog. Null uses the app's surface color.
61+ final ColorRGBA ? backgroundColor;
62+
63+ /// Title and message color of the built-in dialog. Null uses the app's
64+ /// text color.
65+ final ColorRGBA ? textColor;
66+
67+ /// Fill of the built-in dialog's confirm button. Null uses the app's
68+ /// primary color, or its error color when [destructive] .
69+ final ColorRGBA ? confirmColor;
70+
71+ /// Corner radius of the built-in dialog. Null follows the app's buttons.
72+ final double ? cornerRadius;
73+
74+ /// The key of the "Navigate back" params that answers a [dialogId] dialog.
75+ static const String resultKey = 'confirmed' ;
76+
77+ /// Whether a dialog that closed with [result] was confirmed: a map (the
78+ /// params of a "Navigate back" action) whose [resultKey] is true, or true.
79+ static bool isConfirmResult (Object ? result) {
80+ final Object ? value = result is Map ? result[resultKey] : result;
81+ if (value is bool ) return value;
82+ if (value is num ) return value != 0 ;
83+ if (value is String ) {
84+ final String text = value.trim ().toLowerCase ();
85+ return text == 'true' ||
86+ text == 'yes' ||
87+ text == '1' ||
88+ text == 'confirm' ;
89+ }
90+ return false ;
91+ }
92+
3593 /// Creates a [ConfirmAction] .
3694 ConfirmAction ({
3795 required this .title,
@@ -41,10 +99,19 @@ class ConfirmAction extends ActionModel with Equatable, SerializableMixin {
4199 this .destructive = false ,
42100 List <ActionModel >? actions,
43101 List <ActionModel >? cancelActions,
102+ this .dialogId,
103+ Map <String , dynamic >? params,
104+ this .barrierDismissible = true ,
105+ this .barrierColor,
106+ this .backgroundColor,
107+ this .textColor,
108+ this .confirmColor,
109+ this .cornerRadius,
44110 super .nonBlocking,
45111 super .enabled,
46112 }) : actions = actions ?? [],
47113 cancelActions = cancelActions ?? [],
114+ params = params ?? {},
48115 super (type: ActionType .confirm);
49116
50117 /// Duplicates this action with the given values replaced.
@@ -56,6 +123,20 @@ class ConfirmAction extends ActionModel with Equatable, SerializableMixin {
56123 bool ? destructive,
57124 List <ActionModel >? actions,
58125 List <ActionModel >? cancelActions,
126+ String ? dialogId,
127+ bool clearDialogId = false ,
128+ Map <String , dynamic >? params,
129+ bool ? barrierDismissible,
130+ ColorRGBA ? barrierColor,
131+ bool clearBarrierColor = false ,
132+ ColorRGBA ? backgroundColor,
133+ bool clearBackgroundColor = false ,
134+ ColorRGBA ? textColor,
135+ bool clearTextColor = false ,
136+ ColorRGBA ? confirmColor,
137+ bool clearConfirmColor = false ,
138+ double ? cornerRadius,
139+ bool clearCornerRadius = false ,
59140 }) => ConfirmAction (
60141 title: title ?? this .title,
61142 message: message ?? this .message,
@@ -64,6 +145,16 @@ class ConfirmAction extends ActionModel with Equatable, SerializableMixin {
64145 destructive: destructive ?? this .destructive,
65146 actions: actions ?? this .actions,
66147 cancelActions: cancelActions ?? this .cancelActions,
148+ dialogId: clearDialogId ? null : dialogId ?? this .dialogId,
149+ params: params ?? this .params,
150+ barrierDismissible: barrierDismissible ?? this .barrierDismissible,
151+ barrierColor: clearBarrierColor ? null : barrierColor ?? this .barrierColor,
152+ backgroundColor: clearBackgroundColor
153+ ? null
154+ : backgroundColor ?? this .backgroundColor,
155+ textColor: clearTextColor ? null : textColor ?? this .textColor,
156+ confirmColor: clearConfirmColor ? null : confirmColor ?? this .confirmColor,
157+ cornerRadius: clearCornerRadius ? null : cornerRadius ?? this .cornerRadius,
67158 nonBlocking: nonBlocking,
68159 enabled: enabled,
69160 );
@@ -77,6 +168,14 @@ class ConfirmAction extends ActionModel with Equatable, SerializableMixin {
77168 destructive,
78169 actions,
79170 cancelActions,
171+ dialogId,
172+ params,
173+ barrierDismissible,
174+ barrierColor,
175+ backgroundColor,
176+ textColor,
177+ confirmColor,
178+ cornerRadius,
80179 ];
81180
82181 /// Creates an instance from a JSON object.
0 commit comments