Skip to content

Commit 904332f

Browse files
committed
feat: two optional callback added for custom view
1 parent 9f666c0 commit 904332f

File tree

1 file changed

+41
-22
lines changed

1 file changed

+41
-22
lines changed

lib/src/form_builder_image_picker.dart

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ class FormBuilderImagePicker extends FormBuilderField<List<dynamic>> {
100100
/// Either [ImageSourceOption.gallery], [ImageSourceOption.camera] or both.
101101
final List<ImageSourceOption> availableImageSources;
102102

103+
///A callback that returns a pickup options
104+
///ListTile(inside Wrap) by Default
105+
///use optionsBuilder to return a widget of your choice
106+
final ValueChanged<ImageSourceBottomSheet>? onTap;
107+
108+
/// use this callback if you want custom view for options
109+
/// call cameraPicker() to picks image from camera
110+
/// call galleryPicker() to picks image from gallery
111+
final Widget Function(
112+
FutureVoidCallBack cameraPicker, FutureVoidCallBack galleryPicker)?
113+
optionsBuilder;
114+
103115
FormBuilderImagePicker({
104116
Key? key,
105117
//From Super
@@ -140,6 +152,8 @@ class FormBuilderImagePicker extends FormBuilderField<List<dynamic>> {
140152
this.galleryLabel = const Text('Gallery'),
141153
this.bottomSheetPadding = EdgeInsets.zero,
142154
this.placeholderImage,
155+
this.onTap,
156+
this.optionsBuilder,
143157
this.availableImageSources = const [
144158
ImageSourceOption.camera,
145159
ImageSourceOption.gallery,
@@ -197,30 +211,35 @@ class FormBuilderImagePicker extends FormBuilderField<List<dynamic>> {
197211
onTap: () async {
198212
final remainingImages =
199213
maxImages == null ? null : maxImages - value.length;
200-
await showModalBottomSheet<void>(
201-
context: state.context,
202-
builder: (_) {
203-
return ImageSourceBottomSheet(
204-
maxHeight: maxHeight,
205-
maxWidth: maxWidth,
206-
preventPop: preventPop,
207-
remainingImages: remainingImages,
208-
imageQuality: imageQuality,
209-
preferredCameraDevice: preferredCameraDevice,
210-
bottomSheetPadding: bottomSheetPadding,
211-
cameraIcon: cameraIcon,
212-
cameraLabel: cameraLabel,
213-
galleryIcon: galleryIcon,
214-
galleryLabel: galleryLabel,
215-
availableImageSources: availableImageSources,
216-
onImageSelected: (image) {
217-
state.requestFocus();
218-
field.didChange([...value, ...image]);
219-
Navigator.pop(state.context);
220-
},
221-
);
214+
215+
final imageSourceSheet = ImageSourceBottomSheet(
216+
maxHeight: maxHeight,
217+
maxWidth: maxWidth,
218+
preventPop: preventPop,
219+
remainingImages: remainingImages,
220+
imageQuality: imageQuality,
221+
preferredCameraDevice: preferredCameraDevice,
222+
bottomSheetPadding: bottomSheetPadding,
223+
cameraIcon: cameraIcon,
224+
cameraLabel: cameraLabel,
225+
galleryIcon: galleryIcon,
226+
galleryLabel: galleryLabel,
227+
optionsBuilder: optionsBuilder,
228+
availableImageSources: availableImageSources,
229+
onImageSelected: (image) {
230+
state.requestFocus();
231+
field.didChange([...value, ...image]);
232+
Navigator.pop(state.context);
222233
},
223234
);
235+
onTap != null
236+
? onTap(imageSourceSheet)
237+
: await showModalBottomSheet<void>(
238+
context: state.context,
239+
builder: (_) {
240+
return imageSourceSheet;
241+
},
242+
);
224243
},
225244
);
226245

0 commit comments

Comments
 (0)