Skip to content

Commit 7d9b054

Browse files
committed
Added option to disable cancellation
Added Select All / Deselect All to checkbox selection
1 parent 4d33c0f commit 7d9b054

20 files changed

+155
-32
lines changed

Diff for: example/lib/main.dart

+11-7
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,17 @@ class _TestPageState extends State<TestPage> {
239239
child: ElevatedButton(
240240
child: const Text('Checkbox Picker'),
241241
onPressed: () => showMaterialCheckboxPicker<PickerModel>(
242-
context: context,
243-
title: 'Pick Your Toppings',
244-
items: ExampleModel.iceCreamToppings,
245-
selectedItems: model.selectedIceCreamToppings,
246-
onChanged: (value) =>
247-
setState(() => model.selectedIceCreamToppings = value),
248-
),
242+
context: context,
243+
title: 'Pick Your Toppings',
244+
items: ExampleModel.iceCreamToppings,
245+
selectedItems: model.selectedIceCreamToppings,
246+
onChanged: (value) =>
247+
setState(() => model.selectedIceCreamToppings = value),
248+
selectAllConfig: SelectAllConfig(
249+
const Text('Select All'),
250+
const Text('Deselect All'),
251+
),
252+
cancellable: false),
249253
),
250254
),
251255
Expanded(

Diff for: example/windows/flutter/generated_plugins.cmake

+8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
list(APPEND FLUTTER_PLUGIN_LIST
66
)
77

8+
list(APPEND FLUTTER_FFI_PLUGIN_LIST
9+
)
10+
811
set(PLUGIN_BUNDLED_LIBRARIES)
912

1013
foreach(plugin ${FLUTTER_PLUGIN_LIST})
@@ -13,3 +16,8 @@ foreach(plugin ${FLUTTER_PLUGIN_LIST})
1316
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
1417
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
1518
endforeach(plugin)
19+
20+
foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
21+
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin})
22+
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
23+
endforeach(ffi_plugin)

Diff for: lib/dialogs/checkbox_picker_dialog.dart

+23-14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// is governed by the MIT license that can be found in the LICENSE file.
33

44
import 'package:flutter/material.dart';
5+
import 'package:flutter_material_pickers/models/select_all_config.dart';
56
import 'package:flutter_material_pickers/pickers/checkbox_picker.dart';
67

78
import '../flutter_material_pickers.dart';
@@ -12,20 +13,22 @@ import 'responsive_dialog.dart';
1213
/// It is designed to be used in the showDialog method of other fields.
1314
class CheckboxPickerDialog<T> extends StatefulWidget
1415
implements ICommonDialogProperties {
15-
CheckboxPickerDialog({
16-
this.title,
17-
required this.items,
18-
required this.selectedItems,
19-
this.transformer,
20-
this.headerColor,
21-
this.headerTextColor,
22-
this.backgroundColor,
23-
this.buttonTextColor,
24-
this.maxLongSide,
25-
this.maxShortSide,
26-
this.confirmText,
27-
this.cancelText,
28-
});
16+
CheckboxPickerDialog(
17+
{this.title,
18+
required this.items,
19+
required this.selectedItems,
20+
this.transformer,
21+
this.headerColor,
22+
this.headerTextColor,
23+
this.backgroundColor,
24+
this.buttonTextColor,
25+
this.maxLongSide,
26+
this.maxShortSide,
27+
this.confirmText,
28+
this.cancelButtonVisible = true,
29+
this.cancelText,
30+
this.onSelectionChanged,
31+
this.selectAllConfig});
2932

3033
// Variables
3134
final List<T> items;
@@ -49,6 +52,9 @@ class CheckboxPickerDialog<T> extends StatefulWidget
4952
final String? confirmText;
5053
@override
5154
final String? cancelText;
55+
final ValueChanged<List<T>>? onSelectionChanged;
56+
final SelectAllConfig? selectAllConfig;
57+
final bool cancelButtonVisible;
5258

5359
@override
5460
State<CheckboxPickerDialog> createState() =>
@@ -78,10 +84,13 @@ class _CheckboxPickerDialogState<T> extends State<CheckboxPickerDialog<T>> {
7884
maxShortSide: widget.maxLongSide,
7985
confirmText: widget.confirmText,
8086
cancelText: widget.cancelText,
87+
cancelButtonVisible: widget.cancelButtonVisible,
8188
child: CheckboxPicker<T>(
8289
items: widget.items,
8390
selectedItems: selectedItems,
8491
transformer: widget.transformer,
92+
onSelectionChanged: widget.onSelectionChanged,
93+
selectAllConfig: widget.selectAllConfig,
8594
),
8695
okPressed: () => Navigator.of(context).pop(selectedItems),
8796
);

Diff for: lib/dialogs/radio_picker_dialog.dart

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class RadioPickerDialog<T> extends StatefulWidget
2525
this.maxShortSide,
2626
this.confirmText,
2727
this.cancelText,
28+
this.cancelButtonVisible = true,
2829
});
2930

3031
// Variables
@@ -49,6 +50,7 @@ class RadioPickerDialog<T> extends StatefulWidget
4950
final String? confirmText;
5051
@override
5152
final String? cancelText;
53+
final bool cancelButtonVisible;
5254

5355
@override
5456
State<RadioPickerDialog> createState() =>
@@ -73,6 +75,7 @@ class _RadioPickerDialogState<T> extends State<RadioPickerDialog<T>> {
7375
maxShortSide: widget.maxLongSide,
7476
confirmText: widget.confirmText,
7577
cancelText: widget.cancelText,
78+
cancelButtonVisible: widget.cancelButtonVisible,
7679
child: RadioPicker<T>(
7780
items: widget.items,
7881
initialValue: selectedItem,

Diff for: lib/dialogs/responsive_dialog.dart

+13-9
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class ResponsiveDialog extends StatefulWidget
2828
this.cancelPressed,
2929
this.confirmText,
3030
this.cancelText,
31+
this.cancelButtonVisible = true,
3132
}) : title = title ?? "Title Here",
3233
child = child ?? Text("Content Here"),
3334
maxLongSide = maxLongSide ?? 600,
@@ -56,6 +57,7 @@ class ResponsiveDialog extends StatefulWidget
5657
final String? confirmText;
5758
@override
5859
final String? cancelText;
60+
final bool cancelButtonVisible;
5961

6062
// Events
6163
final VoidCallback? cancelPressed;
@@ -108,15 +110,17 @@ class _ResponsiveDialogState extends State<ResponsiveDialog> {
108110
),
109111
child: ButtonBar(
110112
children: <Widget>[
111-
TextButton(
112-
child: Text(
113-
widget.cancelText ?? localizations.cancelButtonLabel,
114-
style: TextStyle(color: _buttonTextColor),
115-
),
116-
onPressed: () => (widget.cancelPressed == null)
117-
? Navigator.of(context).pop()
118-
: widget.cancelPressed!(),
119-
),
113+
widget.cancelButtonVisible
114+
? TextButton(
115+
child: Text(
116+
widget.cancelText ?? localizations.cancelButtonLabel,
117+
style: TextStyle(color: _buttonTextColor),
118+
),
119+
onPressed: () => (widget.cancelPressed == null)
120+
? Navigator.of(context).pop()
121+
: widget.cancelPressed!(),
122+
)
123+
: Container(),
120124
TextButton(
121125
child: Text(
122126
widget.confirmText ?? localizations.okButtonLabel,

Diff for: lib/dialogs/scroll_picker_dialog.dart

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class ScrollPickerDialog<T> extends StatefulWidget
2626
this.showDivider: true,
2727
this.confirmText,
2828
this.cancelText,
29+
this.cancelButtonVisible = true,
2930
});
3031

3132
// Variables
@@ -50,6 +51,7 @@ class ScrollPickerDialog<T> extends StatefulWidget
5051
final String? confirmText;
5152
@override
5253
final String? cancelText;
54+
final bool cancelButtonVisible;
5355

5456
final bool showDivider;
5557

@@ -76,6 +78,7 @@ class _ScrollPickerDialogState<T> extends State<ScrollPickerDialog<T>> {
7678
maxShortSide: widget.maxLongSide,
7779
confirmText: widget.confirmText,
7880
cancelText: widget.cancelText,
81+
cancelButtonVisible: widget.cancelButtonVisible,
7982
child: ScrollPicker<T>(
8083
items: widget.items,
8184
selectedItem: selectedItem,

Diff for: lib/dialogs/selection_picker_dialog.dart

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class SelectionPickerDialog<T> extends StatefulWidget
2626
this.maxShortSide,
2727
this.confirmText,
2828
this.cancelText,
29+
this.cancelButtonVisible = true,
2930
});
3031

3132
final List<T> items;
@@ -50,6 +51,7 @@ class SelectionPickerDialog<T> extends StatefulWidget
5051
final String? confirmText;
5152
@override
5253
final String? cancelText;
54+
final bool cancelButtonVisible;
5355

5456
@override
5557
State<SelectionPickerDialog> createState() =>
@@ -74,6 +76,7 @@ class _SelectionPickerDialogState<T> extends State<SelectionPickerDialog<T>> {
7476
maxShortSide: widget.maxLongSide,
7577
confirmText: widget.confirmText,
7678
cancelText: widget.cancelText,
79+
cancelButtonVisible: widget.cancelButtonVisible,
7780
child: SelectionPicker<T>(
7881
items: widget.items,
7982
initialValue: selectedItem,

Diff for: lib/flutter_material_pickers.dart

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export 'package:flutter_material_pickers/helpers/show_responsive_dialog.dart';
1818

1919
/// Models
2020
export 'package:flutter_material_pickers/models/picker_model.dart';
21+
export 'package:flutter_material_pickers/models/select_all_config.dart';
2122

2223
/// Helpers
2324
export 'package:flutter_material_pickers/helpers/show_scroll_picker.dart';

Diff for: lib/helpers/show_checkbox_picker.dart

+14
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import 'package:flutter/material.dart';
55
import 'package:flutter_material_pickers/dialogs/checkbox_picker_dialog.dart';
6+
import 'package:flutter_material_pickers/models/select_all_config.dart';
67

78
import '../flutter_material_pickers.dart';
89

@@ -34,6 +35,9 @@ Future<List<T>?> showMaterialCheckboxPicker<T>({
3435
/// Text to display in the confirm button
3536
String? confirmText,
3637

38+
/// Whether to display a cancel button
39+
bool cancellable = true,
40+
3741
/// Text to display in the cancel button
3842
String? cancelText,
3943

@@ -46,6 +50,12 @@ Future<List<T>?> showMaterialCheckboxPicker<T>({
4650
/// Function that gets called when the value is changed
4751
ValueChanged<List<T>>? onChanged,
4852

53+
/// Function that gets called each time the selection changes
54+
ValueChanged<List<T>>? onSelectionChanged,
55+
56+
/// If enabled, adds a Select All / Deselect All button at the top
57+
SelectAllConfig? selectAllConfig,
58+
4959
/// Function that gets called when the confirm button is pressed
5060
VoidCallback? onConfirmed,
5161

@@ -58,6 +68,7 @@ Future<List<T>?> showMaterialCheckboxPicker<T>({
5868
}) {
5969
return showDialog<List<T>>(
6070
context: context,
71+
barrierDismissible: cancellable,
6172
builder: (BuildContext context) {
6273
return CheckboxPickerDialog<T>(
6374
title: title,
@@ -72,6 +83,9 @@ Future<List<T>?> showMaterialCheckboxPicker<T>({
7283
maxLongSide: maxLongSide,
7384
maxShortSide: maxLongSide,
7485
transformer: transformer,
86+
onSelectionChanged: onSelectionChanged,
87+
selectAllConfig: selectAllConfig,
88+
cancelButtonVisible: cancellable,
7589
);
7690
},
7791
).then((selection) {

Diff for: lib/helpers/show_color_picker.dart

+5
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,15 @@ Future<Color?> showMaterialColorPicker({
4545
/// Function that gets called when the confirm button is pressed
4646
VoidCallback? onConfirmed,
4747

48+
/// Whether to display a cancel button
49+
bool cancellable = true,
50+
4851
/// Function that gets called when the cancel button is pressed
4952
VoidCallback? onCancelled,
5053
}) {
5154
return showDialog<Color>(
5255
context: context,
56+
barrierDismissible: cancellable,
5357
builder: (BuildContext context) {
5458
return OrientationBuilder(
5559
builder: (context, orientation) {
@@ -65,6 +69,7 @@ Future<Color?> showMaterialColorPicker({
6569
maxLongSide: maxLongSide,
6670
maxShortSide: maxLongSide,
6771
forcePortrait: true,
72+
cancelButtonVisible: cancellable,
6873
child: SingleChildScrollView(
6974
child: ColorPicker(
7075
pickerColor: selectedColor,

Diff for: lib/helpers/show_date_picker.dart

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ Future<DateTime?> showMaterialDatePicker({
3535
/// Text to display in the confirm button
3636
String? confirmText,
3737

38+
/// Whether to display a cancel button
39+
bool cancellable = true,
40+
3841
/// Text to display in the cancel button
3942
String? cancelText,
4043

@@ -55,6 +58,7 @@ Future<DateTime?> showMaterialDatePicker({
5558
}) {
5659
return showDialog<DateTime>(
5760
context: context,
61+
barrierDismissible: cancellable,
5862
builder: (BuildContext context) {
5963
return OrientationBuilder(
6064
builder: (context, orientation) {
@@ -69,6 +73,7 @@ Future<DateTime?> showMaterialDatePicker({
6973
cancelText: cancelText,
7074
maxLongSide: maxLongSide,
7175
maxShortSide: maxLongSide,
76+
cancelButtonVisible: cancellable,
7277
child: SingleChildScrollView(
7378
child: CalendarDatePicker(
7479
initialDate: selectedDate,

Diff for: lib/helpers/show_number_picker.dart

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ Future<int?> showMaterialNumberPicker({
4040
/// Text to display in the confirm button
4141
String? confirmText,
4242

43+
/// Whether to display a cancel button
44+
bool cancellable = true,
45+
4346
/// Text to display in the cancel button
4447
String? cancelText,
4548

@@ -70,6 +73,7 @@ Future<int?> showMaterialNumberPicker({
7073

7174
return showDialog<int>(
7275
context: context,
76+
barrierDismissible: cancellable,
7377
builder: (BuildContext context) {
7478
return ScrollPickerDialog<int>(
7579
items: items,
@@ -81,6 +85,7 @@ Future<int?> showMaterialNumberPicker({
8185
buttonTextColor: buttonTextColor,
8286
confirmText: confirmText,
8387
cancelText: cancelText,
88+
cancelButtonVisible: cancellable,
8489
maxLongSide: maxLongSide,
8590
maxShortSide: maxLongSide,
8691
);

Diff for: lib/helpers/show_palette_picker.dart

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ Future<Color?> showMaterialPalettePicker({
3030
/// Text to display in the confirm button
3131
String? confirmText,
3232

33+
/// Whether to display a cancel button
34+
bool cancellable = true,
35+
3336
/// Text to display in the cancel button
3437
String? cancelText,
3538

@@ -50,6 +53,7 @@ Future<Color?> showMaterialPalettePicker({
5053
}) {
5154
return showDialog<Color>(
5255
context: context,
56+
barrierDismissible: cancellable,
5357
builder: (BuildContext context) {
5458
return OrientationBuilder(
5559
builder: (context, orientation) {

0 commit comments

Comments
 (0)