Skip to content

Commit d6beb12

Browse files
feat: migrate to new form field widget
1 parent ed34274 commit d6beb12

6 files changed

+90
-183
lines changed

lib/src/fields/form_builder_color_picker.dart

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extension on Color {
3030
enum ColorPickerType { colorPicker, materialPicker, blockPicker }
3131

3232
/// Creates a field for `Color` input selection
33-
class FormBuilderColorPickerField extends FormBuilderField<Color> {
33+
class FormBuilderColorPickerField extends FormBuilderFieldDecoration<Color> {
3434
//TODO: Add documentation
3535
final TextEditingController? controller;
3636
final ColorPickerType colorPickerType;
@@ -70,19 +70,18 @@ class FormBuilderColorPickerField extends FormBuilderField<Color> {
7070
final Widget Function(Color?)? colorPreviewBuilder;
7171

7272
FormBuilderColorPickerField({
73-
Key? key,
74-
//From Super
75-
required String name,
76-
FormFieldValidator<Color>? validator,
77-
Color? initialValue,
78-
InputDecoration decoration = const InputDecoration(),
79-
ValueChanged<Color?>? onChanged,
80-
ValueTransformer<Color?>? valueTransformer,
81-
bool enabled = true,
82-
FormFieldSetter<Color>? onSaved,
83-
AutovalidateMode autovalidateMode = AutovalidateMode.disabled,
84-
VoidCallback? onReset,
85-
FocusNode? focusNode,
73+
super.key,
74+
required super.name,
75+
super.validator,
76+
super.initialValue,
77+
super.decoration,
78+
super.onChanged,
79+
super.valueTransformer,
80+
super.enabled,
81+
super.onSaved,
82+
super.autovalidateMode,
83+
super.onReset,
84+
super.focusNode,
8685
bool readOnly = false,
8786
this.colorPickerType = ColorPickerType.colorPicker,
8887
this.textCapitalization = TextCapitalization.none,
@@ -115,18 +114,6 @@ class FormBuilderColorPickerField extends FormBuilderField<Color> {
115114
this.colorPreviewBuilder,
116115
this.availableColors = const [],
117116
}) : super(
118-
key: key,
119-
initialValue: initialValue,
120-
name: name,
121-
validator: validator,
122-
valueTransformer: valueTransformer,
123-
onChanged: onChanged,
124-
autovalidateMode: autovalidateMode,
125-
onSaved: onSaved,
126-
enabled: enabled,
127-
onReset: onReset,
128-
decoration: decoration,
129-
focusNode: focusNode,
130117
builder: (FormFieldState<Color?> field) {
131118
final state = field as FormBuilderColorPickerFieldState;
132119
return TextField(
@@ -183,8 +170,8 @@ class FormBuilderColorPickerField extends FormBuilderField<Color> {
183170
FormBuilderColorPickerFieldState();
184171
}
185172

186-
class FormBuilderColorPickerFieldState
187-
extends FormBuilderFieldState<FormBuilderColorPickerField, Color> {
173+
class FormBuilderColorPickerFieldState extends FormBuilderFieldDecorationState<
174+
FormBuilderColorPickerField, Color> {
188175
late TextEditingController _effectiveController;
189176

190177
String? get valueString => value?.toHex();

lib/src/fields/form_builder_rating_bar.dart

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'package:flutter_form_builder/flutter_form_builder.dart';
33
import 'package:flutter_rating_bar/flutter_rating_bar.dart';
44

55
/// Field for selection of a numerical value using a star* rating widget
6-
class FormBuilderRatingBar extends FormBuilderField<double> {
6+
class FormBuilderRatingBar extends FormBuilderFieldDecoration<double> {
77
/// Defines color for glow.
88
///
99
/// Default is [ThemeData.colorScheme.secondary].
@@ -95,19 +95,18 @@ class FormBuilderRatingBar extends FormBuilderField<double> {
9595
final RatingWidget? ratingWidget;
9696

9797
FormBuilderRatingBar({
98-
Key? key,
99-
//From Super
100-
AutovalidateMode autovalidateMode = AutovalidateMode.disabled,
101-
bool enabled = true,
102-
double? initialValue,
103-
FocusNode? focusNode,
104-
FormFieldSetter<double>? onSaved,
105-
FormFieldValidator<double>? validator,
106-
InputDecoration decoration = const InputDecoration(),
107-
required String name,
108-
ValueChanged<double?>? onChanged,
109-
ValueTransformer<double?>? valueTransformer,
110-
VoidCallback? onReset,
98+
super.key,
99+
super.autovalidateMode,
100+
super.enabled,
101+
super.initialValue,
102+
super.focusNode,
103+
super.onSaved,
104+
super.validator,
105+
super.decoration,
106+
required super.name,
107+
super.onChanged,
108+
super.valueTransformer,
109+
super.onReset,
111110
this.allowHalfRating = false,
112111
this.direction = Axis.horizontal,
113112
this.glow = true,
@@ -126,18 +125,6 @@ class FormBuilderRatingBar extends FormBuilderField<double> {
126125
this.updateOnDrag = false,
127126
this.wrapAlignment = WrapAlignment.start,
128127
}) : super(
129-
key: key,
130-
initialValue: initialValue,
131-
name: name,
132-
validator: validator,
133-
valueTransformer: valueTransformer,
134-
onChanged: onChanged,
135-
autovalidateMode: autovalidateMode,
136-
onSaved: onSaved,
137-
enabled: enabled,
138-
onReset: onReset,
139-
decoration: decoration,
140-
focusNode: focusNode,
141128
builder: (FormFieldState<double?> field) {
142129
final state = field as FormBuilderRatingBarState;
143130
final widget = state.widget;
@@ -182,4 +169,4 @@ class FormBuilderRatingBar extends FormBuilderField<double> {
182169
}
183170

184171
class FormBuilderRatingBarState
185-
extends FormBuilderFieldState<FormBuilderRatingBar, double> {}
172+
extends FormBuilderFieldDecorationState<FormBuilderRatingBar, double> {}

lib/src/fields/form_builder_searchable_dropdown.dart

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
33
import 'package:flutter_form_builder/flutter_form_builder.dart';
44

55
/// Field for selecting value(s) from a searchable list
6-
class FormBuilderSearchableDropdown<T> extends FormBuilderField<T> {
6+
class FormBuilderSearchableDropdown<T> extends FormBuilderFieldDecoration<T> {
77
///offline items list
88
final List<T> items;
99

@@ -89,18 +89,18 @@ class FormBuilderSearchableDropdown<T> extends FormBuilderField<T> {
8989

9090
/// Creates field for selecting value(s) from a searchable list
9191
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,
92+
super.key,
93+
super.autovalidateMode,
94+
super.enabled,
95+
super.focusNode,
96+
super.onSaved,
97+
super.validator,
98+
super.decoration,
99+
required super.name,
100+
super.initialValue,
101+
super.onChanged,
102+
super.valueTransformer,
103+
super.onReset,
104104
this.asyncItems,
105105
this.autoValidateMode,
106106
this.compareFn,
@@ -134,18 +134,6 @@ class FormBuilderSearchableDropdown<T> extends FormBuilderField<T> {
134134
popupValidationMultiSelectionWidget = null,
135135
popupCustomMultiSelectionWidget = null,
136136
super(
137-
key: key,
138-
initialValue: initialValue,
139-
name: name,
140-
validator: validator,
141-
valueTransformer: valueTransformer,
142-
onChanged: onChanged,
143-
autovalidateMode: autovalidateMode,
144-
onSaved: onSaved,
145-
enabled: enabled,
146-
onReset: onReset,
147-
decoration: decoration,
148-
focusNode: focusNode,
149137
builder: (FormFieldState<T?> field) {
150138
final state = field as FormBuilderSearchableDropdownState<T>;
151139
return DropdownSearch<T>(
@@ -182,4 +170,5 @@ class FormBuilderSearchableDropdown<T> extends FormBuilderField<T> {
182170
}
183171

184172
class FormBuilderSearchableDropdownState<T>
185-
extends FormBuilderFieldState<FormBuilderSearchableDropdown<T>, T> {}
173+
extends FormBuilderFieldDecorationState<FormBuilderSearchableDropdown<T>,
174+
T> {}

lib/src/fields/form_builder_signature_pad.dart

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'package:flutter_form_builder/flutter_form_builder.dart';
66
import 'package:signature/signature.dart';
77

88
/// Field with drawing pad on which user can doodle
9-
class FormBuilderSignaturePad extends FormBuilderField<Uint8List> {
9+
class FormBuilderSignaturePad extends FormBuilderFieldDecoration<Uint8List> {
1010
/// Controls the value of the signature pad.
1111
///
1212
/// If null, this widget will create its own [SignatureController].
@@ -37,38 +37,25 @@ class FormBuilderSignaturePad extends FormBuilderField<Uint8List> {
3737

3838
/// Creates field with drawing pad on which user can doodle
3939
FormBuilderSignaturePad({
40-
Key? key,
41-
//From Super
42-
required String name,
43-
FormFieldValidator<Uint8List>? validator,
44-
Uint8List? initialValue,
45-
InputDecoration decoration = const InputDecoration(),
46-
ValueChanged<Uint8List?>? onChanged,
47-
ValueTransformer<Uint8List?>? valueTransformer,
48-
bool enabled = true,
49-
FormFieldSetter<Uint8List>? onSaved,
50-
AutovalidateMode autovalidateMode = AutovalidateMode.disabled,
51-
VoidCallback? onReset,
52-
FocusNode? focusNode,
40+
super.key,
41+
required super.name,
42+
super.validator,
43+
super.initialValue,
44+
super.decoration,
45+
super.onChanged,
46+
super.valueTransformer,
47+
super.enabled,
48+
super.onSaved,
49+
super.autovalidateMode,
50+
super.onReset,
51+
super.focusNode,
5352
this.backgroundColor = Colors.transparent,
5453
this.clearButtonText,
5554
this.width,
5655
this.height = 200,
5756
this.controller,
5857
this.border,
5958
}) : super(
60-
autovalidateMode: autovalidateMode,
61-
decoration: decoration,
62-
enabled: enabled,
63-
focusNode: focusNode,
64-
initialValue: initialValue,
65-
key: key,
66-
name: name,
67-
onChanged: onChanged,
68-
onReset: onReset,
69-
onSaved: onSaved,
70-
validator: validator,
71-
valueTransformer: valueTransformer,
7259
builder: (FormFieldState<Uint8List?> field) {
7360
final state = field as FormBuilderSignaturePadState;
7461
final theme = Theme.of(state.context);
@@ -85,12 +72,9 @@ class FormBuilderSignaturePad extends FormBuilderField<Uint8List> {
8572
width: width,
8673
decoration: BoxDecoration(
8774
border: border,
88-
image:
89-
(null != initialValue && initialValue == state.value)
90-
? DecorationImage(
91-
image: MemoryImage(state.value!),
92-
)
93-
: null,
75+
image: null != initialValue && initialValue == state.value
76+
? DecorationImage(image: MemoryImage(state.value!))
77+
: null,
9478
),
9579
child: state.enabled
9680
? GestureDetector(
@@ -133,8 +117,8 @@ class FormBuilderSignaturePad extends FormBuilderField<Uint8List> {
133117
FormBuilderSignaturePadState createState() => FormBuilderSignaturePadState();
134118
}
135119

136-
class FormBuilderSignaturePadState
137-
extends FormBuilderFieldState<FormBuilderSignaturePad, Uint8List> {
120+
class FormBuilderSignaturePadState extends FormBuilderFieldDecorationState<
121+
FormBuilderSignaturePad, Uint8List> {
138122
late SignatureController _controller;
139123

140124
SignatureController get effectiveController => _controller;

lib/src/fields/form_builder_touch_spin.dart

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import 'package:intl/intl.dart';
55
import '../widgets/touch_spin/touch_spin.dart';
66

77
/// Field for selection of a number by tapping on an add or subtract icon
8-
class FormBuilderTouchSpin extends FormBuilderField<num> {
8+
class FormBuilderTouchSpin extends FormBuilderFieldDecoration<num> {
99
/// Value to increment or decrement by
1010
final num step;
1111

@@ -45,19 +45,18 @@ class FormBuilderTouchSpin extends FormBuilderField<num> {
4545

4646
/// Creates field for selection of a number by tapping on an add or subtract icon
4747
FormBuilderTouchSpin({
48-
Key? key,
49-
//From Super
50-
AutovalidateMode autovalidateMode = AutovalidateMode.disabled,
51-
bool enabled = true,
52-
FocusNode? focusNode,
53-
FormFieldSetter<num>? onSaved,
54-
FormFieldValidator<num>? validator,
55-
InputDecoration decoration = const InputDecoration(),
56-
num? initialValue,
57-
required String name,
58-
ValueChanged<num?>? onChanged,
59-
ValueTransformer<num?>? valueTransformer,
60-
VoidCallback? onReset,
48+
super.key,
49+
super.autovalidateMode,
50+
super.enabled,
51+
super.focusNode,
52+
super.onSaved,
53+
super.validator,
54+
super.decoration,
55+
super.initialValue,
56+
required super.name,
57+
super.onChanged,
58+
super.valueTransformer,
59+
super.onReset,
6160
this.addIcon = const Icon(Icons.add),
6261
this.displayFormat,
6362
this.iconActiveColor,
@@ -70,18 +69,6 @@ class FormBuilderTouchSpin extends FormBuilderField<num> {
7069
this.subtractIcon = const Icon(Icons.remove),
7170
this.textStyle = const TextStyle(fontSize: 24),
7271
}) : super(
73-
autovalidateMode: autovalidateMode,
74-
decoration: decoration,
75-
enabled: enabled,
76-
focusNode: focusNode,
77-
initialValue: initialValue,
78-
key: key,
79-
name: name,
80-
onChanged: onChanged,
81-
onReset: onReset,
82-
onSaved: onSaved,
83-
validator: validator,
84-
valueTransformer: valueTransformer,
8572
builder: (FormFieldState<num?> field) {
8673
final state = field as FormBuilderTouchSpinState;
8774
final theme = Theme.of(state.context);
@@ -118,4 +105,4 @@ class FormBuilderTouchSpin extends FormBuilderField<num> {
118105
}
119106

120107
class FormBuilderTouchSpinState
121-
extends FormBuilderFieldState<FormBuilderTouchSpin, num> {}
108+
extends FormBuilderFieldDecorationState<FormBuilderTouchSpin, num> {}

0 commit comments

Comments
 (0)