@@ -15,9 +15,7 @@ class MyApp extends StatelessWidget {
15
15
Widget build (BuildContext context) {
16
16
return MaterialApp (
17
17
title: 'Flutter Demo' ,
18
- theme: ThemeData (
19
- primarySwatch: Colors .blue,
20
- ),
18
+ theme: ThemeData (primarySwatch: Colors .blue),
21
19
home: MyHomePage (),
22
20
);
23
21
}
@@ -27,10 +25,7 @@ class ApiImage {
27
25
final String imageUrl;
28
26
final String id;
29
27
30
- ApiImage ({
31
- required this .imageUrl,
32
- required this .id,
33
- });
28
+ ApiImage ({required this .imageUrl, required this .id});
34
29
}
35
30
36
31
class MyHomePage extends StatelessWidget {
@@ -41,9 +36,7 @@ class MyHomePage extends StatelessWidget {
41
36
@override
42
37
Widget build (BuildContext context) {
43
38
return Scaffold (
44
- appBar: AppBar (
45
- title: const Text ('FormBuilderImagePicker Example' ),
46
- ),
39
+ appBar: AppBar (title: const Text ('FormBuilderImagePicker Example' )),
47
40
body: Padding (
48
41
padding: const EdgeInsets .all (8.0 ),
49
42
child: Center (
@@ -56,8 +49,8 @@ class MyHomePage extends StatelessWidget {
56
49
children: < Widget > [
57
50
FormBuilderImagePicker (
58
51
name: 'photos' ,
59
- displayCustomType: (obj) =>
60
- obj is ApiImage ? obj.imageUrl : obj,
52
+ displayCustomType:
53
+ (obj) => obj is ApiImage ? obj.imageUrl : obj,
61
54
decoration: const InputDecoration (labelText: 'Pick Photos' ),
62
55
maxImages: 5 ,
63
56
previewAutoSizeWidth: true ,
@@ -76,8 +69,8 @@ class MyHomePage extends StatelessWidget {
76
69
const SizedBox (height: 15 ),
77
70
FormBuilderImagePicker (
78
71
name: 'singlePhotoWithDecoration' ,
79
- displayCustomType: (obj) =>
80
- obj is ApiImage ? obj.imageUrl : obj,
72
+ displayCustomType:
73
+ (obj) => obj is ApiImage ? obj.imageUrl : obj,
81
74
decoration: const InputDecoration (
82
75
labelText: 'Pick Single Photo With Decoration Visible' ,
83
76
),
@@ -90,11 +83,12 @@ class MyHomePage extends StatelessWidget {
90
83
),
91
84
const SizedBox (height: 15 ),
92
85
const Text (
93
- 'Single Photo with no decoration, and previewAutoSizeWidth=true' ),
86
+ 'Single Photo with no decoration, and previewAutoSizeWidth=true' ,
87
+ ),
94
88
FormBuilderImagePicker (
95
89
name: 'singlePhoto' ,
96
- displayCustomType: (obj) =>
97
- obj is ApiImage ? obj.imageUrl : obj,
90
+ displayCustomType:
91
+ (obj) => obj is ApiImage ? obj.imageUrl : obj,
98
92
// decoration: const InputDecoration(
99
93
// labelText: 'Pick Photos',
100
94
// ),
@@ -111,18 +105,15 @@ class MyHomePage extends StatelessWidget {
111
105
),
112
106
FormBuilderImagePicker (
113
107
name: 'singleAvatarPhoto' ,
114
- displayCustomType: (obj) =>
115
- obj is ApiImage ? obj.imageUrl : obj,
116
- decoration: const InputDecoration (
117
- labelText: 'Pick Photos' ,
118
- ),
119
- transformImageWidget: (context, displayImage) => Card (
120
- shape: const CircleBorder (),
121
- clipBehavior: Clip .antiAlias,
122
- child: SizedBox .expand (
123
- child: displayImage,
124
- ),
125
- ),
108
+ displayCustomType:
109
+ (obj) => obj is ApiImage ? obj.imageUrl : obj,
110
+ decoration: const InputDecoration (labelText: 'Pick Photos' ),
111
+ transformImageWidget:
112
+ (context, displayImage) => Card (
113
+ shape: const CircleBorder (),
114
+ clipBehavior: Clip .antiAlias,
115
+ child: SizedBox .expand (child: displayImage),
116
+ ),
126
117
showDecoration: false ,
127
118
maxImages: 1 ,
128
119
previewAutoSizeWidth: false ,
@@ -144,62 +135,71 @@ class MyHomePage extends StatelessWidget {
144
135
FormBuilderImagePicker (
145
136
name: 'onlyCamera' ,
146
137
decoration: const InputDecoration (
147
- labelText: 'Pick Photos (only from camera)' ),
138
+ labelText: 'Pick Photos (only from camera)' ,
139
+ ),
148
140
availableImageSources: const [ImageSourceOption .camera],
149
141
),
150
142
const SizedBox (height: 15 ),
151
143
FormBuilderImagePicker (
152
144
name: 'onlyGallery' ,
153
145
decoration: const InputDecoration (
154
- labelText: 'Pick Photos (only from gallery)' ),
146
+ labelText: 'Pick Photos (only from gallery)' ,
147
+ ),
155
148
availableImageSources: const [ImageSourceOption .gallery],
156
149
),
157
150
FormBuilderImagePicker (
158
151
decoration: const InputDecoration (
159
- labelText: 'Pick Photos (with custom view)' ),
152
+ labelText: 'Pick Photos (with custom view)' ,
153
+ ),
160
154
name: 'CupertinoActionSheet' ,
161
- optionsBuilder: (cameraPicker, galleryPicker) =>
162
- CupertinoActionSheet (
163
- title: const Text ('Image' ),
164
- message: const Text ('Pick an image from given options' ),
165
- actions: [
166
- CupertinoActionSheetAction (
167
- isDefaultAction: true ,
168
- onPressed: () {
169
- cameraPicker ();
170
- },
171
- child: const Text ('Camera' ),
155
+ optionsBuilder:
156
+ (cameraPicker, galleryPicker) => CupertinoActionSheet (
157
+ title: const Text ('Image' ),
158
+ message: const Text (
159
+ 'Pick an image from given options' ,
160
+ ),
161
+ actions: [
162
+ CupertinoActionSheetAction (
163
+ isDefaultAction: true ,
164
+ onPressed: () {
165
+ cameraPicker ();
166
+ },
167
+ child: const Text ('Camera' ),
168
+ ),
169
+ CupertinoActionSheetAction (
170
+ isDefaultAction: true ,
171
+ onPressed: () {
172
+ galleryPicker ();
173
+ },
174
+ child: const Text ('Gallery' ),
175
+ ),
176
+ ],
177
+ ),
178
+ onTap:
179
+ (child) => showCupertinoModalPopup (
180
+ context: context,
181
+ builder: (context) => child,
172
182
),
173
- CupertinoActionSheetAction (
174
- isDefaultAction: true ,
175
- onPressed: () {
176
- galleryPicker ();
177
- },
178
- child: const Text ('Gallery' ),
179
- )
180
- ],
181
- ),
182
- onTap: (child) => showCupertinoModalPopup (
183
- context: context,
184
- builder: (context) => child,
185
- ),
186
183
),
187
184
FormBuilderImagePicker (
188
185
name: 'customPreview' ,
189
186
maxImages: null ,
190
- previewBuilder: (context, images, addButton) =>
191
- ConstrainedBox (
192
- constraints: const BoxConstraints (
193
- minHeight: 130 ,
194
- maxHeight: 500 ,
195
- ),
196
- child: GridView .extent (
197
- maxCrossAxisExtent: 130 ,
198
- mainAxisSpacing: 4 ,
199
- crossAxisSpacing: 4 ,
200
- children: [...images, if (addButton != null ) addButton],
201
- ),
202
- ),
187
+ previewBuilder:
188
+ (context, images, addButton) => ConstrainedBox (
189
+ constraints: const BoxConstraints (
190
+ minHeight: 130 ,
191
+ maxHeight: 500 ,
192
+ ),
193
+ child: GridView .extent (
194
+ maxCrossAxisExtent: 130 ,
195
+ mainAxisSpacing: 4 ,
196
+ crossAxisSpacing: 4 ,
197
+ children: [
198
+ ...images,
199
+ if (addButton != null ) addButton,
200
+ ],
201
+ ),
202
+ ),
203
203
),
204
204
ElevatedButton (
205
205
child: const Text ('Submit' ),
@@ -214,7 +214,7 @@ class MyHomePage extends StatelessWidget {
214
214
onPressed: () {
215
215
_formKey.currentState? .reset ();
216
216
},
217
- )
217
+ ),
218
218
],
219
219
),
220
220
),
0 commit comments