@@ -7,7 +7,9 @@ class FormBuilderImagePicker extends StatefulWidget {
7
7
final List <FormFieldValidator > validators;
8
8
final List initialValue;
9
9
final bool readOnly;
10
+ @Deprecated ('Set the `labelText` within decoration attribute' )
10
11
final String labelText;
12
+ final InputDecoration decoration;
11
13
final ValueTransformer valueTransformer;
12
14
final ValueChanged onChanged;
13
15
@@ -28,7 +30,8 @@ class FormBuilderImagePicker extends StatefulWidget {
28
30
this .imageHeight = 130 ,
29
31
this .imageMargin,
30
32
this .readOnly = false ,
31
- this .onSaved
33
+ this .onSaved,
34
+ this .decoration = const InputDecoration (),
32
35
}) : super (key: key);
33
36
34
37
@override
@@ -84,69 +87,78 @@ class _FormBuilderImagePickerState extends State<FormBuilderImagePicker> {
84
87
widget.onSaved (transformed ?? val);
85
88
}
86
89
},
87
- builder: (state) => Column (
88
- crossAxisAlignment: CrossAxisAlignment .start,
89
- children: < Widget > [
90
- Text (
91
- widget.labelText != null ? widget.labelText : 'Images' ,
92
- style: TextStyle (
93
- color: _readOnly ? Theme .of (context).disabledColor : Theme .of (context).primaryColor
94
- ),
90
+ builder: (field) {
91
+ return InputDecorator (
92
+ decoration: widget.decoration.copyWith (
93
+ enabled: ! _readOnly,
94
+ errorText: field.errorText,
95
+ // ignore: deprecated_member_use_from_same_package
96
+ labelText: widget.decoration.labelText ?? widget.labelText,
95
97
),
96
- SizedBox (
97
- height: 8 ,
98
- ),
99
- Container (
100
- height: widget.imageHeight,
101
- child: ListView (
102
- scrollDirection: Axis .horizontal,
103
- children: state.value.map <Widget >((item) {
104
- return Container (
105
- width: widget.imageWidth,
106
- height: widget.imageHeight,
107
- margin: widget.imageMargin,
108
- child: GestureDetector (
109
- child: item is String ?
110
- Image .network (item, fit: BoxFit .cover) :
111
- Image .file (item, fit: BoxFit .cover),
112
- onLongPress: _readOnly ? null : () {
113
- state.didChange (state.value..remove (item));
114
- },
115
- ),
116
- );
117
- }).toList ()
118
- ..add (
119
- GestureDetector (
120
- child: Container (
121
- width: widget.imageWidth,
122
- height: widget.imageHeight,
123
- child: Icon (
124
- Icons .camera_enhance,
125
- color: _readOnly ? Theme .of (context).disabledColor : Theme .of (context).primaryColor
126
- ),
127
- color: (_readOnly ? Theme .of (context).disabledColor : Theme .of (context).primaryColor).withAlpha (50 )
98
+ child: Column (
99
+ crossAxisAlignment: CrossAxisAlignment .start,
100
+ children: < Widget > [
101
+ SizedBox (
102
+ height: 8 ,
103
+ ),
104
+ Container (
105
+ height: widget.imageHeight,
106
+ child: ListView (
107
+ scrollDirection: Axis .horizontal,
108
+ children: field.value.map <Widget >((item) {
109
+ return Container (
110
+ width: widget.imageWidth,
111
+ height: widget.imageHeight,
112
+ margin: widget.imageMargin,
113
+ child: GestureDetector (
114
+ child: item is String
115
+ ? Image .network (item, fit: BoxFit .cover)
116
+ : Image .file (item, fit: BoxFit .cover),
117
+ onLongPress: _readOnly
118
+ ? null
119
+ : () {
120
+ field.didChange (
121
+ [...field.value]..remove (item));
122
+ },
123
+ ),
124
+ );
125
+ }).toList ()
126
+ ..add (
127
+ GestureDetector (
128
+ child: Container (
129
+ width: widget.imageWidth,
130
+ height: widget.imageHeight,
131
+ child: Icon (Icons .camera_enhance,
132
+ color: _readOnly
133
+ ? Theme .of (context).disabledColor
134
+ : Theme .of (context).primaryColor),
135
+ color: (_readOnly
136
+ ? Theme .of (context).disabledColor
137
+ : Theme .of (context).primaryColor)
138
+ .withAlpha (50 )),
139
+ onTap: _readOnly
140
+ ? null
141
+ : () {
142
+ showModalBottomSheet (
143
+ context: context,
144
+ builder: (_) {
145
+ return ImageSourceSheet (
146
+ onImageSelected: (image) {
147
+ field.didChange (
148
+ [...field.value, image]);
149
+ Navigator .of (context).pop ();
150
+ },
151
+ );
152
+ },
153
+ );
154
+ },
128
155
),
129
- onTap: _readOnly ? null : () {
130
- showModalBottomSheet (context: context, builder: (_) {
131
- return ImageSourceSheet (
132
- onImageSelected: (image) {
133
- state.didChange (state.value..add (image));
134
- Navigator .of (context).pop ();
135
- },
136
- );
137
- });
138
- },
139
- )
140
- )
141
- ),
156
+ )),
157
+ ),
158
+ ],
142
159
),
143
- state.hasError
144
- ? Text (
145
- state.errorText,
146
- style: TextStyle (color: Theme .of (context).errorColor, fontSize: 12 ),
147
- ) : Container ()
148
- ],
149
- ),
160
+ );
161
+ },
150
162
);
151
163
}
152
164
}
0 commit comments