@@ -7,9 +7,6 @@ import 'package:flutter_form_builder/flutter_form_builder.dart';
7
7
class FormBuilderSearchableDropdown <T > extends FormBuilderField <T > {
8
8
final bool shouldRequestFocus;
9
9
10
- ///show/hide the search box
11
- final bool showSearchBox;
12
-
13
10
///true if the filter on items is applied onlie (via API)
14
11
final bool isFilteredOnline;
15
12
@@ -25,9 +22,6 @@ class FormBuilderSearchableDropdown<T> extends FormBuilderField<T> {
25
22
///selected items
26
23
final List <T > selectedItems;
27
24
28
- ///function that returns item from API
29
- final DropdownSearchOnFind <T >? onFind;
30
-
31
25
///called when a new items are selected
32
26
final ValueChanged <List <T >>? onChangedMultiSelection;
33
27
@@ -37,137 +31,38 @@ class FormBuilderSearchableDropdown<T> extends FormBuilderField<T> {
37
31
///to customize list of items UI in MultiSelection mode
38
32
final DropdownSearchBuilderMultiSelection <T >? dropdownBuilderMultiSelection;
39
33
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
-
49
34
///customize the fields the be shown
50
35
final DropdownSearchItemAsString <T >? itemAsString;
51
36
52
37
/// custom filter function
53
38
final DropdownSearchFilterFn <T >? filterFn;
54
39
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
-
67
40
///function that compares two object with the same type to detected if it's the selected item or not
68
41
final DropdownSearchCompareFn <T >? compareFn;
69
42
70
43
///dropdownSearch input decoration
71
44
final InputDecoration ? dropdownSearchDecoration;
72
45
73
46
/// style on which to base the label
74
- final TextStyle ? dropdownSearchBaseStyle;
47
+ // final TextStyle? dropdownSearchBaseStyle;
75
48
76
49
/// How the text in the decoration should be aligned horizontally.
77
50
final TextAlign ? dropdownSearchTextAlign;
78
51
79
52
/// How the text should be aligned vertically.
80
53
final TextAlignVertical ? dropdownSearchTextAlignVertical;
81
54
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
-
94
55
final AutovalidateMode ? autoValidateMode;
95
56
96
57
/// An optional method to call with the final value when the form is saved via
97
58
final FormFieldSetter <List <T >>? onSavedMultiSelection;
98
59
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
-
141
60
/// callback executed before applying value change
142
61
final BeforeChange <T >? onBeforeChange;
143
62
144
63
/// callback executed before applying values changes
145
64
final BeforeChangeMultiSelection <T >? onBeforeChangeMultiSelection;
146
65
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
-
171
66
///define whatever we are in multi selection mode or single selection mode
172
67
final bool isMultiSelectionMode;
173
68
@@ -184,91 +79,57 @@ class FormBuilderSearchableDropdown<T> extends FormBuilderField<T> {
184
79
final ValidationMultiSelectionBuilder <T ?>?
185
80
popupValidationMultiSelectionWidget;
186
81
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 ;
189
84
190
- /// function to override position calculation
191
- final PositionCallback ? positionCallback ;
85
+ ///function that returns item from API
86
+ final DropdownSearchOnFind < T > ? asyncItems ;
192
87
193
- final dropdown_search. SelectionListViewProps selectionListViewProps ;
88
+ final PopupProps < T > popupProps ;
194
89
195
90
/// 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 (
272
133
key: key,
273
134
initialValue: initialValue,
274
135
name: name,
@@ -287,63 +148,27 @@ class FormBuilderSearchableDropdown<T> extends FormBuilderField<T> {
287
148
// Hack to rebuild when didChange is called
288
149
key: UniqueKey (),
289
150
items: items,
290
- maxHeight: maxHeight,
291
- onFind: onFind,
292
151
onChanged: (value) {
293
152
if (shouldRequestFocus) {
294
153
state.requestFocus ();
295
154
}
296
155
state.didChange (value);
297
156
},
298
- selectionListViewProps: selectionListViewProps,
299
- showSearchBox: showSearchBox,
300
157
enabled: state.enabled,
301
158
autoValidateMode: autovalidateMode,
302
- clearButton: clearButton,
303
159
compareFn: compareFn,
304
- dialogMaxWidth: dialogMaxWidth,
305
160
dropdownBuilder: dropdownBuilder,
306
- dropdownBuilderSupportsNullItem: dropdownBuilderSupportsNullItem,
307
- dropDownButton: dropDownButton,
308
161
dropdownSearchDecoration: state.decoration,
309
- emptyBuilder: emptyBuilder,
310
- errorBuilder: errorBuilder,
311
162
filterFn: filterFn,
312
163
isFilteredOnline: isFilteredOnline,
313
164
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,
322
165
selectedItem: state.value,
323
166
showClearButton: showClearButton,
324
- clearButtonBuilder: clearButtonBuilder,
325
- dropdownButtonBuilder: dropdownButtonBuilder,
326
- favoriteItemBuilder: favoriteItemBuilder,
327
- favoriteItems: favoriteItems,
328
167
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,
337
168
dropdownSearchTextAlign: dropdownSearchTextAlign,
338
169
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,
347
172
);
348
173
},
349
174
);
0 commit comments