Skip to content

Commit 62bfc5d

Browse files
authored
Merge pull request #29 from RudreshNarwal/master
web support
2 parents 8f11f4f + 414618a commit 62bfc5d

File tree

3 files changed

+31
-28
lines changed

3 files changed

+31
-28
lines changed

example/pubspec.lock

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ packages:
7070
name: file_picker
7171
url: "https://pub.dartlang.org"
7272
source: hosted
73-
version: "4.2.0"
73+
version: "4.6.1"
7474
flutter:
7575
dependency: "direct main"
7676
description: flutter
@@ -113,7 +113,7 @@ packages:
113113
path: ".."
114114
relative: true
115115
source: path
116-
version: "2.0.0"
116+
version: "2.1.0"
117117
intl:
118118
dependency: transitive
119119
description:
@@ -266,6 +266,13 @@ packages:
266266
url: "https://pub.dartlang.org"
267267
source: hosted
268268
version: "2.1.1"
269+
win32:
270+
dependency: transitive
271+
description:
272+
name: win32
273+
url: "https://pub.dartlang.org"
274+
source: hosted
275+
version: "2.5.2"
269276
sdks:
270277
dart: ">=2.15.0 <3.0.0"
271278
flutter: ">=2.8.0"

lib/src/form_builder_file_picker.dart

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class FormBuilderFilePicker extends FormBuilderField<List<PlatformFile>> {
7878
VoidCallback? onReset,
7979
FocusNode? focusNode,
8080
this.maxFiles,
81-
this.withData = false,
81+
this.withData = kIsWeb,
8282
this.withReadStream = false,
8383
this.allowMultiple = false,
8484
this.previewImages = true,
@@ -111,12 +111,9 @@ class FormBuilderFilePicker extends FormBuilderField<List<PlatformFile>> {
111111
Row(
112112
mainAxisAlignment: MainAxisAlignment.spaceBetween,
113113
children: <Widget>[
114-
if (maxFiles != null)
115-
Text('${state._files.length} / $maxFiles'),
114+
if (maxFiles != null) Text('${state._files.length} / $maxFiles'),
116115
InkWell(
117-
onTap: state.enabled &&
118-
(null == state._remainingItemCount ||
119-
state._remainingItemCount! > 0)
116+
onTap: state.enabled && (null == state._remainingItemCount || state._remainingItemCount! > 0)
120117
? () => state.pickFiles(field)
121118
: null,
122119
child: selector,
@@ -125,10 +122,8 @@ class FormBuilderFilePicker extends FormBuilderField<List<PlatformFile>> {
125122
),
126123
const SizedBox(height: 3),
127124
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)),
132127
],
133128
),
134129
);
@@ -139,8 +134,7 @@ class FormBuilderFilePicker extends FormBuilderField<List<PlatformFile>> {
139134
_FormBuilderFilePickerState createState() => _FormBuilderFilePickerState();
140135
}
141136

142-
class _FormBuilderFilePickerState
143-
extends FormBuilderFieldState<FormBuilderFilePicker, List<PlatformFile>> {
137+
class _FormBuilderFilePickerState extends FormBuilderFieldState<FormBuilderFilePicker, List<PlatformFile>> {
144138
/// Image File Extensions.
145139
///
146140
/// Note that images may be previewed.
@@ -162,8 +156,7 @@ class _FormBuilderFilePickerState
162156

163157
List<PlatformFile> _files = [];
164158

165-
int? get _remainingItemCount =>
166-
widget.maxFiles == null ? null : widget.maxFiles! - _files.length;
159+
int? get _remainingItemCount => widget.maxFiles == null ? null : widget.maxFiles! - _files.length;
167160

168161
@override
169162
void initState() {
@@ -203,8 +196,7 @@ class _FormBuilderFilePickerState
203196
}
204197
}
205198

206-
void _setFiles(
207-
List<PlatformFile> files, FormFieldState<List<PlatformFile>?> field) {
199+
void _setFiles(List<PlatformFile> files, FormFieldState<List<PlatformFile>?> field) {
208200
setState(() => _files = files);
209201
field.didChange(_files);
210202
}
@@ -214,16 +206,14 @@ class _FormBuilderFilePickerState
214206
field.didChange(_files);
215207
}
216208

217-
Widget defaultFileViewer(
218-
List<PlatformFile> files, FormFieldSetter<List<PlatformFile>> setter) {
209+
Widget defaultFileViewer(List<PlatformFile> files, FormFieldSetter<List<PlatformFile>> setter) {
219210
final theme = Theme.of(context);
220211

221212
return LayoutBuilder(
222213
builder: (context, constraints) {
223214
const count = 3;
224215
const spacing = 10;
225-
final itemSize =
226-
(constraints.biggest.width - (count * spacing)) / count;
216+
final itemSize = (constraints.biggest.width - (count * spacing)) / count;
227217
return Wrap(
228218
// scrollDirection: Axis.horizontal,
229219
alignment: WrapAlignment.start,
@@ -242,11 +232,10 @@ class _FormBuilderFilePickerState
242232
children: <Widget>[
243233
Container(
244234
alignment: Alignment.center,
245-
child: (imageFileExts.contains(
246-
files[index].extension!.toLowerCase()) &&
247-
widget.previewImages)
248-
? Image.file(File(files[index].path!),
249-
fit: BoxFit.cover)
235+
child: (imageFileExts.contains(files[index].extension!.toLowerCase()) && widget.previewImages)
236+
? kIsWeb
237+
? Image.memory(files[index].bytes!, fit: BoxFit.cover)
238+
: Image.file(File(files[index].path!), fit: BoxFit.cover)
250239
: Container(
251240
alignment: Alignment.center,
252241
color: theme.primaryColor,

pubspec.lock

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ packages:
7070
name: file_picker
7171
url: "https://pub.dartlang.org"
7272
source: hosted
73-
version: "4.2.0"
73+
version: "4.6.1"
7474
flutter:
7575
dependency: "direct main"
7676
description: flutter
@@ -259,6 +259,13 @@ packages:
259259
url: "https://pub.dartlang.org"
260260
source: hosted
261261
version: "2.1.1"
262+
win32:
263+
dependency: transitive
264+
description:
265+
name: win32
266+
url: "https://pub.dartlang.org"
267+
source: hosted
268+
version: "2.5.2"
262269
sdks:
263270
dart: ">=2.15.0 <3.0.0"
264271
flutter: ">=2.8.0"

0 commit comments

Comments
 (0)