Skip to content

Commit 77a2341

Browse files
style: apply new dart format
1 parent c2b378a commit 77a2341

File tree

2 files changed

+84
-92
lines changed

2 files changed

+84
-92
lines changed

example/lib/main.dart

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ class MyHomePage extends StatelessWidget {
4949
children: <Widget>[
5050
FormBuilderImagePicker(
5151
name: 'photos',
52-
displayCustomType:
53-
(obj) => obj is ApiImage ? obj.imageUrl : obj,
52+
displayCustomType: (obj) =>
53+
obj is ApiImage ? obj.imageUrl : obj,
5454
decoration: const InputDecoration(labelText: 'Pick Photos'),
5555
maxImages: 5,
5656
previewAutoSizeWidth: true,
@@ -70,8 +70,8 @@ class MyHomePage extends StatelessWidget {
7070
const SizedBox(height: 15),
7171
FormBuilderImagePicker(
7272
name: 'singlePhotoWithDecoration',
73-
displayCustomType:
74-
(obj) => obj is ApiImage ? obj.imageUrl : obj,
73+
displayCustomType: (obj) =>
74+
obj is ApiImage ? obj.imageUrl : obj,
7575
decoration: const InputDecoration(
7676
labelText: 'Pick Single Photo With Decoration Visible',
7777
),
@@ -88,8 +88,8 @@ class MyHomePage extends StatelessWidget {
8888
),
8989
FormBuilderImagePicker(
9090
name: 'singlePhoto',
91-
displayCustomType:
92-
(obj) => obj is ApiImage ? obj.imageUrl : obj,
91+
displayCustomType: (obj) =>
92+
obj is ApiImage ? obj.imageUrl : obj,
9393
// decoration: const InputDecoration(
9494
// labelText: 'Pick Photos',
9595
// ),
@@ -106,15 +106,14 @@ class MyHomePage extends StatelessWidget {
106106
),
107107
FormBuilderImagePicker(
108108
name: 'singleAvatarPhoto',
109-
displayCustomType:
110-
(obj) => obj is ApiImage ? obj.imageUrl : obj,
109+
displayCustomType: (obj) =>
110+
obj is ApiImage ? obj.imageUrl : obj,
111111
decoration: const InputDecoration(labelText: 'Pick Photos'),
112-
transformImageWidget:
113-
(context, displayImage) => Card(
114-
shape: const CircleBorder(),
115-
clipBehavior: Clip.antiAlias,
116-
child: SizedBox.expand(child: displayImage),
117-
),
112+
transformImageWidget: (context, displayImage) => Card(
113+
shape: const CircleBorder(),
114+
clipBehavior: Clip.antiAlias,
115+
child: SizedBox.expand(child: displayImage),
116+
),
118117
showDecoration: false,
119118
maxImages: 1,
120119
previewAutoSizeWidth: false,
@@ -153,8 +152,8 @@ class MyHomePage extends StatelessWidget {
153152
labelText: 'Pick Photos (with custom view)',
154153
),
155154
name: 'CupertinoActionSheet',
156-
optionsBuilder:
157-
(cameraPicker, galleryPicker) => CupertinoActionSheet(
155+
optionsBuilder: (cameraPicker, galleryPicker) =>
156+
CupertinoActionSheet(
158157
title: const Text('Image'),
159158
message: const Text(
160159
'Pick an image from given options',
@@ -176,17 +175,16 @@ class MyHomePage extends StatelessWidget {
176175
),
177176
],
178177
),
179-
onTap:
180-
(child) => showCupertinoModalPopup(
181-
context: context,
182-
builder: (context) => child,
183-
),
178+
onTap: (child) => showCupertinoModalPopup(
179+
context: context,
180+
builder: (context) => child,
181+
),
184182
),
185183
FormBuilderImagePicker(
186184
name: 'customPreview',
187185
maxImages: null,
188-
previewBuilder:
189-
(context, images, addButton) => ConstrainedBox(
186+
previewBuilder: (context, images, addButton) =>
187+
ConstrainedBox(
190188
constraints: const BoxConstraints(
191189
minHeight: 130,
192190
maxHeight: 500,

lib/src/form_builder_image_picker.dart

Lines changed: 63 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -195,27 +195,24 @@ class FormBuilderImagePicker extends FormBuilderFieldDecoration<List<dynamic>> {
195195
placeholderWidget ??
196196
SizedBox(
197197
width: previewWidth,
198-
child:
199-
placeholderImage != null
200-
? Image(image: placeholderImage)
201-
: Container(
202-
color:
203-
(state.enabled
204-
? backgroundColor ??
205-
primaryColor.withAlpha(50)
206-
: disabledColor),
207-
child: Icon(
208-
icon ?? Icons.camera_enhance,
209-
color:
210-
state.enabled
211-
? iconColor ?? primaryColor
212-
: disabledColor,
213-
),
198+
child: placeholderImage != null
199+
? Image(image: placeholderImage)
200+
: Container(
201+
color: (state.enabled
202+
? backgroundColor ?? primaryColor.withAlpha(50)
203+
: disabledColor),
204+
child: Icon(
205+
icon ?? Icons.camera_enhance,
206+
color: state.enabled
207+
? iconColor ?? primaryColor
208+
: disabledColor,
214209
),
210+
),
215211
),
216212
onTap: () async {
217-
final remainingImages =
218-
maxImages == null ? null : maxImages - value.length;
213+
final remainingImages = maxImages == null
214+
? null
215+
: maxImages - value.length;
219216

220217
final imageSourceSheet = ImageSourceBottomSheet(
221218
maxHeight: maxHeight,
@@ -240,12 +237,12 @@ class FormBuilderImagePicker extends FormBuilderFieldDecoration<List<dynamic>> {
240237
onTap != null
241238
? onTap(imageSourceSheet)
242239
: await showModalBottomSheet<void>(
243-
context: state.context,
244-
clipBehavior: optionsClipBehavior,
245-
builder: (_) {
246-
return imageSourceSheet;
247-
},
248-
);
240+
context: state.context,
241+
clipBehavior: optionsClipBehavior,
242+
builder: (_) {
243+
return imageSourceSheet;
244+
},
245+
);
249246
},
250247
);
251248

@@ -268,20 +265,19 @@ class FormBuilderImagePicker extends FormBuilderFieldDecoration<List<dynamic>> {
268265
'Consider using displayCustomType to handle the type: ${displayItem.runtimeType}',
269266
);
270267

271-
final displayWidget =
272-
displayItem is Widget
273-
? displayItem
274-
: displayItem is ImageProvider
275-
? Image(image: displayItem, fit: fit)
276-
: displayItem is Uint8List
277-
? Image.memory(displayItem, fit: fit)
278-
: displayItem is String
279-
? Image.network(displayItem, fit: fit)
280-
: XFileImage(
281-
file: displayItem,
282-
fit: fit,
283-
loadingWidget: loadingWidget,
284-
);
268+
final displayWidget = displayItem is Widget
269+
? displayItem
270+
: displayItem is ImageProvider
271+
? Image(image: displayItem, fit: fit)
272+
: displayItem is Uint8List
273+
? Image.memory(displayItem, fit: fit)
274+
: displayItem is String
275+
? Image.network(displayItem, fit: fit)
276+
: XFileImage(
277+
file: displayItem,
278+
fit: fit,
279+
loadingWidget: loadingWidget,
280+
);
285281
return Stack(
286282
key: ObjectKey(item),
287283
children: <Widget>[
@@ -320,10 +316,9 @@ class FormBuilderImagePicker extends FormBuilderFieldDecoration<List<dynamic>> {
320316
if (previewBuilder != null) {
321317
return Builder(
322318
builder: (context) {
323-
final widgets =
324-
value
325-
.mapIndexed((i, v) => itemBuilder(context, v, i))
326-
.toList();
319+
final widgets = value
320+
.mapIndexed((i, v) => itemBuilder(context, v, i))
321+
.toList();
327322

328323
return previewBuilder(
329324
context,
@@ -336,36 +331,35 @@ class FormBuilderImagePicker extends FormBuilderFieldDecoration<List<dynamic>> {
336331

337332
final child = SizedBox(
338333
height: previewHeight,
339-
child:
340-
itemCount == 0
341-
? null //empty list
342-
: itemCount ==
343-
1 //has a single item,
344-
? canUpload
345-
? addButtonBuilder(state.context) //upload button
346-
: SizedBox(
334+
child: itemCount == 0
335+
? null //empty list
336+
: itemCount ==
337+
1 //has a single item,
338+
? canUpload
339+
? addButtonBuilder(state.context) //upload button
340+
: SizedBox(
347341
width: previewAutoSizeWidth ? null : previewWidth,
348342
child: itemBuilder(state.context, value.first, 0),
349343
)
350-
: ListView.builder(
351-
itemExtent: previewAutoSizeWidth ? null : previewWidth,
352-
scrollDirection: Axis.horizontal,
353-
itemCount: itemCount,
354-
itemBuilder: (context, index) {
355-
return Container(
356-
margin: previewMargin,
357-
child: Builder(
358-
builder: (context) {
359-
if (index < value.length) {
360-
final item = value[index];
361-
return itemBuilder(context, item, index);
362-
}
363-
return addButtonBuilder(context);
364-
},
365-
),
366-
);
367-
},
368-
),
344+
: ListView.builder(
345+
itemExtent: previewAutoSizeWidth ? null : previewWidth,
346+
scrollDirection: Axis.horizontal,
347+
itemCount: itemCount,
348+
itemBuilder: (context, index) {
349+
return Container(
350+
margin: previewMargin,
351+
child: Builder(
352+
builder: (context) {
353+
if (index < value.length) {
354+
final item = value[index];
355+
return itemBuilder(context, item, index);
356+
}
357+
return addButtonBuilder(context);
358+
},
359+
),
360+
);
361+
},
362+
),
369363
);
370364
return showDecoration
371365
? InputDecorator(decoration: state.decoration, child: child)

0 commit comments

Comments
 (0)