Skip to content

Commit

Permalink
Update save behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
PRBaraiya committed Sep 13, 2022
1 parent b1bbfef commit 1184f9b
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 20 deletions.
4 changes: 2 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class _MyHomePageState extends State<MyHomePage> {
buttonText: Text("Favorite Animals"),
title: Text("Animals"),
items: _items,
onConfirm: (values) {
onConfirm: (values, [search]) {
_selectedAnimals2 = values;
},
chipDisplay: MultiSelectChipDisplay(
Expand Down Expand Up @@ -192,7 +192,7 @@ class _MyHomePageState extends State<MyHomePage> {
}
return null;
},
onConfirm: (values) {
onConfirm: (values, [search]) {
setState(() {
_selectedAnimals3 = values;
});
Expand Down
2 changes: 1 addition & 1 deletion lib/bottom_sheet/multi_select_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MultiSelectBottomSheet<T> extends StatefulWidget
final void Function(List<T>)? onSelectionChanged;

/// Fires when confirm is tapped.
final void Function(List<T>)? onConfirm;
final void Function(List<T>, [String?])? onConfirm;

/// Toggles search functionality.
final bool searchable;
Expand Down
13 changes: 6 additions & 7 deletions lib/bottom_sheet/multi_select_bottom_sheet_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MultiSelectBottomSheetField<V> extends FormField<List<V>> {
final void Function(List<V>)? onSelectionChanged;

/// Fires when confirm is tapped.
final void Function(List<V>) onConfirm;
final void Function(List<V>, [String?]) onConfirm;

/// Toggles search functionality.
final bool searchable;
Expand Down Expand Up @@ -221,7 +221,7 @@ class _MultiSelectBottomSheetFieldView<V> extends StatefulWidget {
final List<V>? initialValue;
final Widget? title;
final void Function(List<V>)? onSelectionChanged;
final void Function(List<V>)? onConfirm;
final void Function(List<V>, [String?])? onConfirm;
final bool searchable;
final Text? confirmText;
final Text? cancelText;
Expand Down Expand Up @@ -350,13 +350,12 @@ class __MultiSelectBottomSheetFieldViewState<V>
}
}

void populateSelectedItems(){
if(widget.initialValue != null){
void populateSelectedItems() {
if (widget.initialValue != null) {
_selectedItems = widget.initialValue!;
}
}


Widget _buildInheritedChipDisplay() {
List<MultiSelectItem<V>?> chipDisplayItems = [];
chipDisplayItems = widget.checkCondition == null
Expand Down Expand Up @@ -446,12 +445,12 @@ class __MultiSelectBottomSheetFieldViewState<V>
separateSelectedItems: widget.separateSelectedItems,
initialValue: _selectedItems,
emptyListPlaceHolder: widget.emptyListPlaceHolder,
onConfirm: (selected) {
onConfirm: (selected, [search]) {
if (widget.state != null) {
widget.state!.didChange(selected);
}
_selectedItems = selected;
if (widget.onConfirm != null) widget.onConfirm!(selected);
if (widget.onConfirm != null) widget.onConfirm!(selected, search);
},
onSelectionChanged: widget.onSelectionChanged,
searchable: widget.searchable,
Expand Down
4 changes: 2 additions & 2 deletions lib/custom_bottom_sheet/custom_multi_select_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CustomMultiSelectBottomSheet<T> extends StatefulWidget
final void Function(List<T>)? onSelectionChanged;

/// Fires when confirm is tapped.
final void Function(List<T>)? onConfirm;
final void Function(List<T>, [String?])? onConfirm;

/// Toggles search functionality.
final bool searchable;
Expand Down Expand Up @@ -437,7 +437,7 @@ class _CustomMultiSelectBottomSheetState<T>
child: ElevatedButton(
onPressed: () {
widget.onConfirmTap(
context, _selectedValues, widget.onConfirm);
context, _selectedValues, widget.onConfirm, searchController.text);
},
child: widget.confirmText ??
Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CustomMultiSelectBottomSheetField<V> extends FormField<List<V>> {
final void Function(List<V>)? onSelectionChanged;

/// Fires when confirm is tapped.
final void Function(List<V>) onConfirm;
final void Function(List<V>, [String?]) onConfirm;

/// Toggles search functionality.
final bool searchable;
Expand Down Expand Up @@ -231,7 +231,7 @@ class _MultiSelectBottomSheetFieldView<V> extends StatefulWidget {
final List<V>? initialValue;
final Widget? title;
final void Function(List<V>)? onSelectionChanged;
final void Function(List<V>)? onConfirm;
final void Function(List<V>, [String?])? onConfirm;
final bool searchable;
final Text? confirmText;
final Text? cancelText;
Expand Down Expand Up @@ -471,12 +471,12 @@ class __MultiSelectBottomSheetFieldViewState<V>
separateSelectedItems: widget.separateSelectedItems,
initialValue: _selectedItems,
emptyListPlaceHolder: widget.emptyListPlaceHolder,
onConfirm: (selected) {
onConfirm: (selected, [search]) {
if (widget.state != null) {
widget.state!.didChange(selected);
}
_selectedItems = selected;
if (widget.onConfirm != null) widget.onConfirm!(selected);
if (widget.onConfirm != null) widget.onConfirm!(selected, search);
},
onSelectionChanged: widget.onSelectionChanged,
searchable: widget.searchable,
Expand Down
2 changes: 1 addition & 1 deletion lib/dialog/mult_select_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MultiSelectDialog<T> extends StatefulWidget with MultiSelectActions<T> {
final void Function(List<T>)? onSelectionChanged;

/// Fires when confirm is tapped.
final void Function(List<T>)? onConfirm;
final void Function(List<T>, [String?])? onConfirm;

/// Toggles search functionality. Default is false.
final bool searchable;
Expand Down
2 changes: 1 addition & 1 deletion lib/dialog/multi_select_dialog_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ class __MultiSelectDialogFieldViewState<V>
confirmText: widget.confirmText,
cancelText: widget.cancelText,
separateSelectedItems: widget.separateSelectedItems,
onConfirm: (selected) {
onConfirm: (selected, [search]) {
if (widget.state != null) {
widget.state!.didChange(selected);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/util/multi_select_actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ class MultiSelectActions<T> {
/// Pops the dialog from the navigation stack and returns the selected values.
/// Calls the onConfirm function if one was provided.
void onConfirmTap(
BuildContext ctx, List<T> selectedValues, Function(List<T>)? onConfirm) {
BuildContext ctx, List<T> selectedValues, Function(List<T>, [String?])? onConfirm, [String? searchText]) {
Navigator.pop(ctx, selectedValues);
if (onConfirm != null) {
onConfirm(selectedValues);
onConfirm(selectedValues, searchText);
}
}

Expand Down

0 comments on commit 1184f9b

Please sign in to comment.