Skip to content

Commit ab1f0f1

Browse files
committed
Added decoration attribute to ImagePicker, deprecated labelText
1 parent e409a0b commit ab1f0f1

File tree

1 file changed

+73
-61
lines changed

1 file changed

+73
-61
lines changed

lib/src/fields/form_builder_image_picker.dart

Lines changed: 73 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ class FormBuilderImagePicker extends StatefulWidget {
77
final List<FormFieldValidator> validators;
88
final List initialValue;
99
final bool readOnly;
10+
@Deprecated('Set the `labelText` within decoration attribute')
1011
final String labelText;
12+
final InputDecoration decoration;
1113
final ValueTransformer valueTransformer;
1214
final ValueChanged onChanged;
1315

@@ -28,7 +30,8 @@ class FormBuilderImagePicker extends StatefulWidget {
2830
this.imageHeight = 130,
2931
this.imageMargin,
3032
this.readOnly = false,
31-
this.onSaved
33+
this.onSaved,
34+
this.decoration = const InputDecoration(),
3235
}) : super(key: key);
3336

3437
@override
@@ -84,69 +87,78 @@ class _FormBuilderImagePickerState extends State<FormBuilderImagePicker> {
8487
widget.onSaved(transformed ?? val);
8588
}
8689
},
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,
9597
),
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+
},
128155
),
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+
],
142159
),
143-
state.hasError
144-
? Text(
145-
state.errorText,
146-
style: TextStyle(color: Theme.of(context).errorColor, fontSize: 12),
147-
) : Container()
148-
],
149-
),
160+
);
161+
},
150162
);
151163
}
152164
}

0 commit comments

Comments
 (0)