Skip to content

Commit a00f0be

Browse files
authored
feat: Add option to set toggleable for showConfirmDialog (#123)
I would like to suggest an option to set `toggleable` to `false` in the `showConfirmationDialog` method. This is to deal with cases where user do not want to deselect an item when tapped again. Thanks for the great library.
2 parents 8fa4964 + e16678f commit a00f0be

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/src/alert_dialog/show_confirmation_dialog.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import 'package:meta/meta.dart';
1414
/// for performance optimization.
1515
/// if [initialSelectedActionKey] is set, corresponding action is selected
1616
/// initially. This works only for Android style.
17+
/// [toggleable] option is only supported in material dialog.
18+
/// When set to `false`, the selected action cannot be unselected by tapping.
19+
/// The default value is `true`.
1720
@useResult
1821
Future<T?> showConfirmationDialog<T>({
1922
required BuildContext context,
@@ -32,6 +35,7 @@ Future<T?> showConfirmationDialog<T>({
3235
WillPopCallback? onWillPop,
3336
AdaptiveDialogBuilder? builder,
3437
RouteSettings? routeSettings,
38+
bool toggleable = true,
3539
}) {
3640
void pop({required BuildContext context, required T? key}) => Navigator.of(
3741
context,
@@ -61,6 +65,7 @@ Future<T?> showConfirmationDialog<T>({
6165
shrinkWrap: shrinkWrap,
6266
fullyCapitalized: fullyCapitalizedForMaterial,
6367
onWillPop: onWillPop,
68+
toggleable: toggleable,
6469
);
6570
return builder == null ? dialog : builder(context, dialog);
6671
},
@@ -93,6 +98,7 @@ class _ConfirmationMaterialDialog<T> extends StatefulWidget {
9398
required this.shrinkWrap,
9499
required this.fullyCapitalized,
95100
required this.onWillPop,
101+
required this.toggleable,
96102
});
97103

98104
final String title;
@@ -106,6 +112,7 @@ class _ConfirmationMaterialDialog<T> extends StatefulWidget {
106112
final bool shrinkWrap;
107113
final bool fullyCapitalized;
108114
final WillPopCallback? onWillPop;
115+
final bool toggleable;
109116

110117
@override
111118
_ConfirmationMaterialDialogState<T> createState() =>
@@ -180,7 +187,7 @@ class _ConfirmationMaterialDialogState<T>
180187
_selectedKey = value;
181188
});
182189
},
183-
toggleable: true,
190+
toggleable: widget.toggleable,
184191
),
185192
)
186193
.toList(),

0 commit comments

Comments
 (0)