@@ -78,7 +78,7 @@ class FormBuilderFilePicker extends FormBuilderField<List<PlatformFile>> {
78
78
VoidCallback ? onReset,
79
79
FocusNode ? focusNode,
80
80
this .maxFiles,
81
- this .withData = false ,
81
+ this .withData = kIsWeb ,
82
82
this .withReadStream = false ,
83
83
this .allowMultiple = false ,
84
84
this .previewImages = true ,
@@ -105,18 +105,15 @@ class FormBuilderFilePicker extends FormBuilderField<List<PlatformFile>> {
105
105
final state = field as _FormBuilderFilePickerState ;
106
106
107
107
return InputDecorator (
108
- decoration: decoration,
108
+ decoration: state. decoration,
109
109
child: Column (
110
110
children: < Widget > [
111
111
Row (
112
112
mainAxisAlignment: MainAxisAlignment .spaceBetween,
113
113
children: < Widget > [
114
- if (maxFiles != null )
115
- Text ('${state ._files .length } / $maxFiles ' ),
114
+ if (maxFiles != null ) Text ('${state ._files .length } / $maxFiles ' ),
116
115
InkWell (
117
- onTap: state.enabled &&
118
- (null == state._remainingItemCount ||
119
- state._remainingItemCount! > 0 )
116
+ onTap: state.enabled && (null == state._remainingItemCount || state._remainingItemCount! > 0 )
120
117
? () => state.pickFiles (field)
121
118
: null ,
122
119
child: selector,
@@ -125,10 +122,8 @@ class FormBuilderFilePicker extends FormBuilderField<List<PlatformFile>> {
125
122
),
126
123
const SizedBox (height: 3 ),
127
124
customFileViewerBuilder != null
128
- ? customFileViewerBuilder.call (state._files,
129
- (files) => state._setFiles (files ?? [], field))
130
- : state.defaultFileViewer (state._files,
131
- (files) => state._setFiles (files ?? [], field)),
125
+ ? customFileViewerBuilder.call (state._files, (files) => state._setFiles (files ?? [], field))
126
+ : state.defaultFileViewer (state._files, (files) => state._setFiles (files ?? [], field)),
132
127
],
133
128
),
134
129
);
@@ -140,8 +135,7 @@ class FormBuilderFilePicker extends FormBuilderField<List<PlatformFile>> {
140
135
createState () => _FormBuilderFilePickerState ();
141
136
}
142
137
143
- class _FormBuilderFilePickerState
144
- extends FormBuilderFieldState <FormBuilderFilePicker , List <PlatformFile >> {
138
+ class _FormBuilderFilePickerState extends FormBuilderFieldState <FormBuilderFilePicker , List <PlatformFile >> {
145
139
/// Image File Extensions.
146
140
///
147
141
/// Note that images may be previewed.
@@ -163,8 +157,7 @@ class _FormBuilderFilePickerState
163
157
164
158
List <PlatformFile > _files = [];
165
159
166
- int ? get _remainingItemCount =>
167
- widget.maxFiles == null ? null : widget.maxFiles! - _files.length;
160
+ int ? get _remainingItemCount => widget.maxFiles == null ? null : widget.maxFiles! - _files.length;
168
161
169
162
@override
170
163
void initState () {
@@ -204,8 +197,7 @@ class _FormBuilderFilePickerState
204
197
}
205
198
}
206
199
207
- void _setFiles (
208
- List <PlatformFile > files, FormFieldState <List <PlatformFile >?> field) {
200
+ void _setFiles (List <PlatformFile > files, FormFieldState <List <PlatformFile >?> field) {
209
201
setState (() => _files = files);
210
202
field.didChange (_files);
211
203
}
@@ -215,16 +207,14 @@ class _FormBuilderFilePickerState
215
207
field.didChange (_files);
216
208
}
217
209
218
- Widget defaultFileViewer (
219
- List <PlatformFile > files, FormFieldSetter <List <PlatformFile >> setter) {
210
+ Widget defaultFileViewer (List <PlatformFile > files, FormFieldSetter <List <PlatformFile >> setter) {
220
211
final theme = Theme .of (context);
221
212
222
213
return LayoutBuilder (
223
214
builder: (context, constraints) {
224
215
const count = 3 ;
225
216
const spacing = 10 ;
226
- final itemSize =
227
- (constraints.biggest.width - (count * spacing)) / count;
217
+ final itemSize = (constraints.biggest.width - (count * spacing)) / count;
228
218
return Wrap (
229
219
// scrollDirection: Axis.horizontal,
230
220
alignment: WrapAlignment .start,
@@ -243,11 +233,10 @@ class _FormBuilderFilePickerState
243
233
children: < Widget > [
244
234
Container (
245
235
alignment: Alignment .center,
246
- child: (imageFileExts.contains (
247
- files[index].extension ! .toLowerCase ()) &&
248
- widget.previewImages)
249
- ? Image .file (File (files[index].path! ),
250
- fit: BoxFit .cover)
236
+ child: (imageFileExts.contains (files[index].extension ! .toLowerCase ()) && widget.previewImages)
237
+ ? kIsWeb
238
+ ? Image .memory (files[index].bytes! , fit: BoxFit .cover)
239
+ : Image .file (File (files[index].path! ), fit: BoxFit .cover)
251
240
: Container (
252
241
alignment: Alignment .center,
253
242
color: theme.primaryColor,
0 commit comments