1
+ import 'package:flutter/foundation.dart' ;
1
2
import 'package:flutter/material.dart' ;
2
3
import 'package:flutter_form_builder/flutter_form_builder.dart' ;
3
4
import 'package:flutter_form_builder/src/widgets/image_source_sheet.dart' ;
@@ -29,8 +30,13 @@ class FormBuilderImagePicker extends FormBuilderField {
29
30
30
31
final Function (Image ) onImage;
31
32
final int maxImages;
33
+ final Widget cameraIcon;
34
+ final Widget galleryIcon;
35
+ final Widget cameraLabel;
36
+ final Widget galleryLabel;
37
+ final EdgeInsets bottomSheetPadding;
32
38
33
- FormBuilderImagePicker ({
39
+ FormBuilderImagePicker ( {
34
40
Key key,
35
41
//From Super
36
42
@required String name,
@@ -55,6 +61,11 @@ class FormBuilderImagePicker extends FormBuilderField {
55
61
this .preferredCameraDevice = CameraDevice .rear,
56
62
this .onImage,
57
63
this .maxImages,
64
+ this .cameraIcon = const Icon (Icons .camera_enhance),
65
+ this .galleryIcon = const Icon (Icons .image),
66
+ this .cameraLabel = const Text ('Camera' ),
67
+ this .galleryLabel = const Text ('Gallery' ),
68
+ this .bottomSheetPadding = const EdgeInsets .all (0 ),
58
69
}) : assert (maxImages == null || maxImages >= 0 ),
59
70
super (
60
71
key: key,
@@ -94,9 +105,11 @@ class FormBuilderImagePicker extends FormBuilderField {
94
105
width: previewWidth,
95
106
height: previewHeight,
96
107
margin: previewMargin,
97
- child: item is String
98
- ? Image .network (item, fit: BoxFit .cover)
99
- : Image .file (item, fit: BoxFit .cover),
108
+ child: kIsWeb
109
+ ? Image .memory (item, fit: BoxFit .cover)
110
+ : item is String
111
+ ? Image .network (item, fit: BoxFit .cover)
112
+ : Image .file (item, fit: BoxFit .cover),
100
113
),
101
114
if (! state.readOnly)
102
115
InkWell (
@@ -141,15 +154,27 @@ class FormBuilderImagePicker extends FormBuilderField {
141
154
showModalBottomSheet (
142
155
context: state.context,
143
156
builder: (_) {
144
- return ImageSourceSheet (
157
+ return ImageSourceBottomSheet (
145
158
maxHeight: maxHeight,
146
159
maxWidth: maxWidth,
147
160
imageQuality: imageQuality,
148
161
preferredCameraDevice: preferredCameraDevice,
162
+ bottomSheetPadding: bottomSheetPadding,
163
+ cameraIcon: cameraIcon,
164
+ cameraLabel: cameraLabel,
165
+ galleryIcon: galleryIcon,
166
+ galleryLabel: galleryLabel,
149
167
onImageSelected: (image) {
150
168
state.requestFocus ();
151
- field
152
- .didChange ([...field.value ?? [], image]);
169
+ field.didChange ([
170
+ ...field.value ?? [],
171
+ image,
172
+ ]);
173
+ Navigator .of (state.context).pop ();
174
+ },
175
+ onImage: (image) {
176
+ field.didChange ([...field.value, image]);
177
+ onChanged? .call (field.value);
153
178
Navigator .of (state.context).pop ();
154
179
},
155
180
);
0 commit comments