@@ -7,9 +7,6 @@ import 'package:flutter_form_builder/flutter_form_builder.dart';
77class FormBuilderSearchableDropdown <T > extends FormBuilderField <T > {
88 final bool shouldRequestFocus;
99
10- ///show/hide the search box
11- final bool showSearchBox;
12-
1310 ///true if the filter on items is applied onlie (via API)
1411 final bool isFilteredOnline;
1512
@@ -25,9 +22,6 @@ class FormBuilderSearchableDropdown<T> extends FormBuilderField<T> {
2522 ///selected items
2623 final List <T > selectedItems;
2724
28- ///function that returns item from API
29- final DropdownSearchOnFind <T >? onFind;
30-
3125 ///called when a new items are selected
3226 final ValueChanged <List <T >>? onChangedMultiSelection;
3327
@@ -37,137 +31,38 @@ class FormBuilderSearchableDropdown<T> extends FormBuilderField<T> {
3731 ///to customize list of items UI in MultiSelection mode
3832 final DropdownSearchBuilderMultiSelection <T >? dropdownBuilderMultiSelection;
3933
40- ///to customize selected item
41- final DropdownSearchPopupItemBuilder <T >? popupItemBuilder;
42-
43- ///the title for dialog/menu/bottomSheet
44- final Color ? popupBackgroundColor;
45-
46- ///custom widget for the popup title
47- final Widget ? popupTitle;
48-
4934 ///customize the fields the be shown
5035 final DropdownSearchItemAsString <T >? itemAsString;
5136
5237 /// custom filter function
5338 final DropdownSearchFilterFn <T >? filterFn;
5439
55- ///MENU / DIALOG/ BOTTOM_SHEET
56- final Mode mode;
57-
58- ///the max height for dialog/bottomSheet/Menu
59- final double ? maxHeight;
60-
61- ///the max width for the dialog
62- final double ? dialogMaxWidth;
63-
64- ///select the selected item in the menu/dialog/bottomSheet of items
65- final bool showSelectedItems;
66-
6740 ///function that compares two object with the same type to detected if it's the selected item or not
6841 final DropdownSearchCompareFn <T >? compareFn;
6942
7043 ///dropdownSearch input decoration
7144 final InputDecoration ? dropdownSearchDecoration;
7245
7346 /// style on which to base the label
74- final TextStyle ? dropdownSearchBaseStyle;
47+ // final TextStyle? dropdownSearchBaseStyle;
7548
7649 /// How the text in the decoration should be aligned horizontally.
7750 final TextAlign ? dropdownSearchTextAlign;
7851
7952 /// How the text should be aligned vertically.
8053 final TextAlignVertical ? dropdownSearchTextAlignVertical;
8154
82- ///custom layout for empty results
83- final EmptyBuilder ? emptyBuilder;
84-
85- ///custom layout for loading items
86- final LoadingBuilder ? loadingBuilder;
87-
88- ///custom layout for error
89- final ErrorBuilder ? errorBuilder;
90-
91- ///custom shape for the popup
92- final ShapeBorder ? popupShape;
93-
9455 final AutovalidateMode ? autoValidateMode;
9556
9657 /// An optional method to call with the final value when the form is saved via
9758 final FormFieldSetter <List <T >>? onSavedMultiSelection;
9859
99- ///custom dropdown clear button icon widget
100- final Widget ? clearButton;
101-
102- ///custom clear button widget builder
103- final IconButtonBuilder ? clearButtonBuilder;
104-
105- ///custom splash radius for the clear button
106- ///If null, default splash radius of [icon_button] is used.
107- final double ? clearButtonSplashRadius;
108-
109- ///custom dropdown icon button widget
110- final Widget ? dropDownButton;
111-
112- ///custom dropdown button widget builder
113- final IconButtonBuilder ? dropdownButtonBuilder;
114-
115- ///custom splash radius for the dropdown button
116- ///If null, default splash radius of [icon_button] is used.
117- final double ? dropdownButtonSplashRadius;
118-
119- ///whether to manage the clear and dropdown icons via InputDecoration suffixIcon
120- final bool showAsSuffixIcons;
121-
122- ///If true, the dropdownBuilder will continue the uses of material behavior
123- ///This will be useful if you want to handle a custom UI only if the item !=null
124- final bool dropdownBuilderSupportsNullItem;
125-
126- ///defines if an item of the popup is enabled or not, if the item is disabled,
127- ///it cannot be clicked
128- final DropdownSearchPopupItemEnabled <T >? popupItemDisabled;
129-
130- ///set a custom color for the popup barrier
131- final Color ? popupBarrierColor;
132-
133- ///called when popup is dismissed
134- final VoidCallback ? onPopupDismissed;
135-
136- /// callback executed before applying value change
137- ///delay before searching, change it to Duration(milliseconds: 0)
138- ///if you do not use online search
139- final Duration ? searchDelay;
140-
14160 /// callback executed before applying value change
14261 final BeforeChange <T >? onBeforeChange;
14362
14463 /// callback executed before applying values changes
14564 final BeforeChangeMultiSelection <T >? onBeforeChangeMultiSelection;
14665
147- ///show or hide favorites items
148- final bool showFavoriteItems;
149-
150- ///to customize favorites chips
151- final FavoriteItemsBuilder <T >? favoriteItemBuilder;
152-
153- ///favorites items list
154- final FavoriteItems <T >? favoriteItems;
155-
156- ///favorite items alignment
157- final MainAxisAlignment ? favoriteItemsAlignment;
158-
159- ///set properties of popup safe area
160- final PopupSafeAreaProps popupSafeArea;
161-
162- /// object that passes all props to search field
163- final TextFieldProps ? searchFieldProps;
164-
165- /// scrollbar properties
166- final ScrollbarProps ? scrollbarProps;
167-
168- /// whether modal can be dismissed by tapping the modal barrier
169- final bool popupBarrierDismissible;
170-
17166 ///define whatever we are in multi selection mode or single selection mode
17267 final bool isMultiSelectionMode;
17368
@@ -184,91 +79,57 @@ class FormBuilderSearchableDropdown<T> extends FormBuilderField<T> {
18479 final ValidationMultiSelectionBuilder <T ?>?
18580 popupValidationMultiSelectionWidget;
18681
187- /// elevation for popup items
188- final double popupElevation ;
82+ ///widget to add custom widget like addAll/removeAll on popup multi selection mode
83+ final ValidationMultiSelectionBuilder < T > ? popupCustomMultiSelectionWidget ;
18984
190- /// function to override position calculation
191- final PositionCallback ? positionCallback ;
85+ ///function that returns item from API
86+ final DropdownSearchOnFind < T > ? asyncItems ;
19287
193- final dropdown_search. SelectionListViewProps selectionListViewProps ;
88+ final PopupProps < T > popupProps ;
19489
19590 /// Creates field for selecting value(s) from a searchable list
196- FormBuilderSearchableDropdown ({
197- Key ? key,
198- //From Super
199- AutovalidateMode autovalidateMode = AutovalidateMode .disabled,
200- bool enabled = true ,
201- FocusNode ? focusNode,
202- FormFieldSetter <T >? onSaved,
203- FormFieldValidator <T >? validator,
204- InputDecoration decoration = const InputDecoration (),
205- required String name,
206- T ? initialValue,
207- ValueChanged <T ?>? onChanged,
208- ValueTransformer <T ?>? valueTransformer,
209- VoidCallback ? onReset,
210- this .autoValidateMode,
211- this .clearButton,
212- this .clearButtonBuilder,
213- this .clearButtonSplashRadius,
214- this .compareFn,
215- this .dialogMaxWidth,
216- this .dropdownBuilder,
217- this .dropdownBuilderMultiSelection,
218- this .dropdownBuilderSupportsNullItem = false ,
219- this .dropDownButton,
220- this .dropdownButtonBuilder,
221- this .dropdownButtonSplashRadius,
222- this .dropdownSearchBaseStyle,
223- this .dropdownSearchDecoration,
224- this .dropdownSearchTextAlign,
225- this .dropdownSearchTextAlignVertical,
226- this .emptyBuilder,
227- this .errorBuilder,
228- this .favoriteItemBuilder,
229- this .favoriteItems,
230- this .favoriteItemsAlignment = MainAxisAlignment .start,
231- this .filterFn,
232- this .isFilteredOnline = false ,
233- this .isMultiSelectionMode = false ,
234- this .itemAsString,
235- this .items,
236- this .loadingBuilder,
237- this .maxHeight,
238- this .mode = dropdown_search.Mode .MENU ,
239- this .onBeforeChange,
240- this .onBeforeChangeMultiSelection,
241- this .onChangedMultiSelection,
242- this .onFind,
243- this .onPopupDismissed,
244- this .onSavedMultiSelection,
245- this .popupBackgroundColor,
246- this .popupBarrierColor,
247- this .popupBarrierDismissible = true ,
248- this .popupElevation = 0 ,
249- this .popupItemBuilder,
250- this .popupItemDisabled,
251- this .popupOnItemAdded,
252- this .popupOnItemRemoved,
253- this .popupSafeArea = const PopupSafeAreaProps (),
254- this .popupSelectionWidget,
255- this .popupShape,
256- this .popupTitle,
257- this .popupValidationMultiSelectionWidget,
258- this .positionCallback,
259- this .scrollbarProps,
260- this .searchDelay,
261- this .searchFieldProps,
262- this .selectedItem,
263- this .selectedItems = const [],
264- this .selectionListViewProps = const SelectionListViewProps (),
265- this .shouldRequestFocus = false ,
266- this .showAsSuffixIcons = false ,
267- this .showClearButton = false ,
268- this .showFavoriteItems = false ,
269- this .showSearchBox = true ,
270- this .showSelectedItems = false ,
271- }) : super (
91+ FormBuilderSearchableDropdown (
92+ {Key ? key,
93+ AutovalidateMode autovalidateMode = AutovalidateMode .disabled,
94+ bool enabled = true ,
95+ FocusNode ? focusNode,
96+ FormFieldSetter <T >? onSaved,
97+ FormFieldValidator <T >? validator,
98+ InputDecoration decoration = const InputDecoration (),
99+ required String name,
100+ T ? initialValue,
101+ ValueChanged <T ?>? onChanged,
102+ ValueTransformer <T ?>? valueTransformer,
103+ VoidCallback ? onReset,
104+ this .asyncItems,
105+ this .autoValidateMode,
106+ this .compareFn,
107+ this .dropdownBuilder,
108+ this .dropdownSearchDecoration,
109+ this .dropdownSearchTextAlign,
110+ this .dropdownSearchTextAlignVertical,
111+ this .filterFn,
112+ this .isFilteredOnline = false ,
113+ this .itemAsString,
114+ this .items,
115+ this .onBeforeChange,
116+ this .popupOnItemAdded,
117+ this .popupOnItemRemoved,
118+ this .popupSelectionWidget,
119+ this .selectedItem,
120+ this .selectedItems = const [],
121+ this .shouldRequestFocus = false ,
122+ this .showClearButton = false ,
123+ this .popupProps = const PopupProps .menu ()})
124+ : assert (T == String || compareFn != null ),
125+ isMultiSelectionMode = false ,
126+ dropdownBuilderMultiSelection = null ,
127+ onBeforeChangeMultiSelection = null ,
128+ onSavedMultiSelection = null ,
129+ onChangedMultiSelection = null ,
130+ popupValidationMultiSelectionWidget = null ,
131+ popupCustomMultiSelectionWidget = null ,
132+ super (
272133 key: key,
273134 initialValue: initialValue,
274135 name: name,
@@ -287,63 +148,27 @@ class FormBuilderSearchableDropdown<T> extends FormBuilderField<T> {
287148 // Hack to rebuild when didChange is called
288149 key: UniqueKey (),
289150 items: items,
290- maxHeight: maxHeight,
291- onFind: onFind,
292151 onChanged: (value) {
293152 if (shouldRequestFocus) {
294153 state.requestFocus ();
295154 }
296155 state.didChange (value);
297156 },
298- selectionListViewProps: selectionListViewProps,
299- showSearchBox: showSearchBox,
300157 enabled: state.enabled,
301158 autoValidateMode: autovalidateMode,
302- clearButton: clearButton,
303159 compareFn: compareFn,
304- dialogMaxWidth: dialogMaxWidth,
305160 dropdownBuilder: dropdownBuilder,
306- dropdownBuilderSupportsNullItem: dropdownBuilderSupportsNullItem,
307- dropDownButton: dropDownButton,
308161 dropdownSearchDecoration: state.decoration,
309- emptyBuilder: emptyBuilder,
310- errorBuilder: errorBuilder,
311162 filterFn: filterFn,
312163 isFilteredOnline: isFilteredOnline,
313164 itemAsString: itemAsString,
314- loadingBuilder: loadingBuilder,
315- popupBackgroundColor: popupBackgroundColor,
316- mode: mode,
317- popupBarrierColor: popupBarrierColor,
318- popupItemBuilder: popupItemBuilder,
319- popupItemDisabled: popupItemDisabled,
320- popupShape: popupShape,
321- popupTitle: popupTitle,
322165 selectedItem: state.value,
323166 showClearButton: showClearButton,
324- clearButtonBuilder: clearButtonBuilder,
325- dropdownButtonBuilder: dropdownButtonBuilder,
326- favoriteItemBuilder: favoriteItemBuilder,
327- favoriteItems: favoriteItems,
328167 onBeforeChange: onBeforeChange,
329- favoriteItemsAlignment: favoriteItemsAlignment,
330- onPopupDismissed: onPopupDismissed,
331- searchDelay: searchDelay,
332- showAsSuffixIcons: showAsSuffixIcons,
333- showFavoriteItems: showFavoriteItems,
334- clearButtonSplashRadius: clearButtonSplashRadius,
335- dropdownButtonSplashRadius: dropdownButtonSplashRadius,
336- dropdownSearchBaseStyle: dropdownSearchBaseStyle,
337168 dropdownSearchTextAlign: dropdownSearchTextAlign,
338169 dropdownSearchTextAlignVertical: dropdownSearchTextAlignVertical,
339- // onSaved: onSaved,
340- popupBarrierDismissible: popupBarrierDismissible,
341- popupElevation: popupElevation,
342- popupSafeArea: popupSafeArea,
343- scrollbarProps: scrollbarProps,
344- searchFieldProps: searchFieldProps,
345- showSelectedItems: showSelectedItems,
346- positionCallback: positionCallback,
170+ asyncItems: asyncItems,
171+ popupProps: popupProps,
347172 );
348173 },
349174 );
0 commit comments