Skip to content

Commit 54987d5

Browse files
feat: Remove parameters related to decoration
1 parent 320dd21 commit 54987d5

File tree

3 files changed

+82
-106
lines changed

3 files changed

+82
-106
lines changed

example/lib/main.dart

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,13 @@ class _CompleteFormState extends State<CompleteForm> {
177177
name: 'age',
178178
decoration: InputDecoration(
179179
labelText: 'Age',
180-
suffixIcon: _ageHasError
181-
? const Icon(Icons.error, color: Colors.red)
182-
: const Icon(Icons.check, color: Colors.green),
180+
suffixIcon: IconButton(
181+
icon: const Icon(Icons.plus_one),
182+
onPressed: () {
183+
_formKey.currentState!.fields['age']
184+
?.didChange('14');
185+
},
186+
),
183187
),
184188
onChanged: (val) {
185189
setState(() {
@@ -203,13 +207,15 @@ class _CompleteFormState extends State<CompleteForm> {
203207
name: 'gender',
204208
decoration: InputDecoration(
205209
labelText: 'Gender',
206-
suffix: _genderHasError
207-
? const Icon(Icons.error)
208-
: const Icon(Icons.check),
210+
suffix: IconButton(
211+
icon: const Icon(Icons.close),
212+
onPressed: () {
213+
_formKey.currentState!.fields['gender']?.reset();
214+
},
215+
),
216+
hintText: 'Select Gender',
209217
),
210-
// initialValue: 'Male',
211-
allowClear: true,
212-
hint: const Text('Select Gender'),
218+
initialValue: 'Male',
213219
validator: FormBuilderValidators.compose(
214220
[FormBuilderValidators.required()]),
215221
items: genderOptions

example/lib/sources/complete_form.dart

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,12 @@ class _CompleteFormState extends State<CompleteForm> {
171171
// autovalidate: true,
172172
name: 'gender',
173173
decoration: InputDecoration(
174-
labelText: 'Gender',
175-
suffix: _genderHasError
176-
? const Icon(Icons.error)
177-
: const Icon(Icons.check),
178-
),
174+
labelText: 'Gender',
175+
suffix: _genderHasError
176+
? const Icon(Icons.error)
177+
: const Icon(Icons.check),
178+
hintText: 'Select Gender'),
179179
// initialValue: 'Male',
180-
allowClear: true,
181-
hint: const Text('Select Gender'),
182180
validator: FormBuilderValidators.compose(
183181
[FormBuilderValidators.required()]),
184182
items: genderOptions

lib/src/fields/form_builder_dropdown.dart

Lines changed: 62 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
99
/// If the [onChanged] callback is null or the list of items is null
1010
/// then the dropdown button will be disabled, i.e. its arrow will be
1111
/// displayed in grey and it will not respond to input. A disabled button
12-
/// will display the [disabledHint] widget if it is non-null. If
13-
/// [disabledHint] is also null but [hint] is non-null, [hint] will instead
14-
/// be displayed.
12+
/// will display the [disabledHint] widget if it is non-null.
13+
///
14+
/// If [decoration.hint] and variations is non-null and [disabledHint] is null,
15+
/// the [decoration.hint] widget will be displayed instead.
1516
final List<DropdownMenuItem<T>> items;
1617

1718
/// A placeholder widget that is displayed by the dropdown button.
@@ -23,8 +24,9 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
2324

2425
/// A message to show when the dropdown is disabled.
2526
///
26-
/// Displayed if [items] or [onChanged] is null. If [hint] is non-null and
27-
/// [disabledHint] is null, the [hint] widget will be displayed instead.
27+
/// Displayed if [items] or [onChanged] is null. If [decoration.hint] and
28+
/// variations is non-null and [disabledHint] is null, the [decoration.hint]
29+
/// widget will be displayed instead.
2830
final Widget? disabledHint;
2931

3032
/// Called when the dropdown button is tapped.
@@ -219,40 +221,42 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
219221

220222
/// Defines the corner radii of the menu's rounded rectangle shape.
221223
///
222-
/// The radii of the first menu item's top left and right corners are
224+
/// The radius of the first menu item's top left and right corners are
223225
/// defined by the corresponding properties of the [borderRadius].
224226
/// Similarly, the radii of the last menu item's bottom and right corners
225227
/// are defined by the corresponding properties of the [borderRadius].
226228
final BorderRadius? borderRadius;
227229

228230
/// Creates field for Dropdown button
229231
FormBuilderDropdown({
230-
Key? key,
231-
//From Super
232-
required String name,
233-
FormFieldValidator<T>? validator,
234-
T? initialValue,
235-
InputDecoration decoration = const InputDecoration(),
236-
ValueChanged<T?>? onChanged,
237-
ValueTransformer<T?>? valueTransformer,
238-
bool enabled = true,
239-
FormFieldSetter<T>? onSaved,
240-
AutovalidateMode autovalidateMode = AutovalidateMode.disabled,
241-
VoidCallback? onReset,
242-
FocusNode? focusNode,
232+
super.key,
233+
required super.name,
234+
super.validator,
235+
super.initialValue,
236+
super.decoration,
237+
super.onChanged,
238+
super.valueTransformer,
239+
super.enabled,
240+
super.onSaved,
241+
super.autovalidateMode = AutovalidateMode.disabled,
242+
super.onReset,
243+
super.focusNode,
243244
required this.items,
244245
this.isExpanded = true,
245246
this.isDense = true,
246247
this.elevation = 8,
247248
this.iconSize = 24.0,
248-
this.hint,
249+
@Deprecated('Please use decoration.hint and variations to set your desired label')
250+
this.hint,
249251
this.style,
250252
this.disabledHint,
251253
this.icon,
252254
this.iconDisabledColor,
253255
this.iconEnabledColor,
254-
this.allowClear = false,
255-
this.clearIcon = const Icon(Icons.close),
256+
@Deprecated('Please use decoration.suffix to set your desired behavior')
257+
this.allowClear = false,
258+
@Deprecated('Please use decoration.suffixIcon to set your desired icon')
259+
this.clearIcon = const Icon(Icons.close),
256260
this.onTap,
257261
this.autofocus = false,
258262
this.shouldRequestFocus = false,
@@ -264,23 +268,9 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
264268
this.enableFeedback,
265269
this.borderRadius,
266270
this.alignment = AlignmentDirectional.centerStart,
267-
}) : /*: assert(allowClear == true || clearIcon != null)*/ super(
268-
key: key,
269-
initialValue: initialValue,
270-
name: name,
271-
validator: validator,
272-
valueTransformer: valueTransformer,
273-
onChanged: onChanged,
274-
autovalidateMode: autovalidateMode,
275-
onSaved: onSaved,
276-
enabled: enabled,
277-
onReset: onReset,
278-
decoration: decoration,
279-
focusNode: focusNode,
271+
}) : super(
280272
builder: (FormFieldState<T?> field) {
281273
final state = field as _FormBuilderDropdownState<T>;
282-
// DropdownButtonFormField
283-
// TextFormField
284274

285275
void changeValue(T? value) {
286276
if (shouldRequestFocus) {
@@ -290,60 +280,42 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
290280
}
291281

292282
return InputDecorator(
293-
decoration: state.decoration.copyWith(
294-
floatingLabelBehavior: hint == null
295-
? decoration.floatingLabelBehavior
296-
: FloatingLabelBehavior.always,
297-
),
283+
decoration: state.decoration,
298284
isEmpty: state.value == null,
299-
child: Row(
300-
children: <Widget>[
301-
Expanded(
302-
child: DropdownButtonHideUnderline(
303-
child: DropdownButton<T>(
304-
isExpanded: isExpanded,
305-
hint: hint,
306-
items: items,
307-
value: field.value,
308-
style: style,
309-
isDense: isDense,
310-
disabledHint: field.value != null
311-
? (items
312-
.firstWhereOrNull((dropDownItem) =>
313-
dropDownItem.value == field.value)
314-
?.child ??
315-
Text(field.value.toString()))
316-
: disabledHint,
317-
elevation: elevation,
318-
iconSize: iconSize,
319-
icon: icon,
320-
iconDisabledColor: iconDisabledColor,
321-
iconEnabledColor: iconEnabledColor,
322-
onChanged: state.enabled
323-
? (value) => changeValue(value)
324-
: null,
325-
onTap: onTap,
326-
focusNode: state.effectiveFocusNode,
327-
autofocus: autofocus,
328-
dropdownColor: dropdownColor,
329-
focusColor: focusColor,
330-
itemHeight: itemHeight,
331-
selectedItemBuilder: selectedItemBuilder,
332-
menuMaxHeight: menuMaxHeight,
333-
borderRadius: borderRadius,
334-
enableFeedback: enableFeedback,
335-
alignment: alignment,
336-
),
337-
),
338-
),
339-
if (allowClear && state.enabled && field.value != null) ...[
340-
const VerticalDivider(),
341-
InkWell(
342-
onTap: () => changeValue(null),
343-
child: clearIcon,
344-
),
345-
]
346-
],
285+
child: DropdownButtonHideUnderline(
286+
child: DropdownButton<T>(
287+
isExpanded: isExpanded,
288+
hint: hint,
289+
items: items,
290+
value: field.value,
291+
style: style,
292+
isDense: isDense,
293+
disabledHint: field.value != null
294+
? (items
295+
.firstWhereOrNull((dropDownItem) =>
296+
dropDownItem.value == field.value)
297+
?.child ??
298+
Text(field.value.toString()))
299+
: disabledHint,
300+
elevation: elevation,
301+
iconSize: iconSize,
302+
icon: icon,
303+
iconDisabledColor: iconDisabledColor,
304+
iconEnabledColor: iconEnabledColor,
305+
onChanged:
306+
state.enabled ? (value) => changeValue(value) : null,
307+
onTap: onTap,
308+
focusNode: state.effectiveFocusNode,
309+
autofocus: autofocus,
310+
dropdownColor: dropdownColor,
311+
focusColor: focusColor,
312+
itemHeight: itemHeight,
313+
selectedItemBuilder: selectedItemBuilder,
314+
menuMaxHeight: menuMaxHeight,
315+
borderRadius: borderRadius,
316+
enableFeedback: enableFeedback,
317+
alignment: alignment,
318+
),
347319
),
348320
);
349321
},

0 commit comments

Comments
 (0)