Skip to content

Commit 0663d73

Browse files
committed
# Conflicts: # example/pubspec.lock # pubspec.lock
2 parents 7b23b93 + 62bfc5d commit 0663d73

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

example/lib/generated_plugin_registrant.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
// ignore_for_file: directives_ordering
66
// ignore_for_file: lines_longer_than_80_chars
7+
// ignore_for_file: depend_on_referenced_packages
78

89
import 'package:file_picker/_internal/file_picker_web.dart';
910

lib/src/form_builder_file_picker.dart

Lines changed: 15 additions & 26 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,
@@ -105,18 +105,15 @@ class FormBuilderFilePicker extends FormBuilderField<List<PlatformFile>> {
105105
final state = field as _FormBuilderFilePickerState;
106106

107107
return InputDecorator(
108-
decoration: decoration,
108+
decoration: state.decoration,
109109
child: Column(
110110
children: <Widget>[
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
);
@@ -140,8 +135,7 @@ class FormBuilderFilePicker extends FormBuilderField<List<PlatformFile>> {
140135
createState() => _FormBuilderFilePickerState();
141136
}
142137

143-
class _FormBuilderFilePickerState
144-
extends FormBuilderFieldState<FormBuilderFilePicker, List<PlatformFile>> {
138+
class _FormBuilderFilePickerState extends FormBuilderFieldState<FormBuilderFilePicker, List<PlatformFile>> {
145139
/// Image File Extensions.
146140
///
147141
/// Note that images may be previewed.
@@ -163,8 +157,7 @@ class _FormBuilderFilePickerState
163157

164158
List<PlatformFile> _files = [];
165159

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;
168161

169162
@override
170163
void initState() {
@@ -204,8 +197,7 @@ class _FormBuilderFilePickerState
204197
}
205198
}
206199

207-
void _setFiles(
208-
List<PlatformFile> files, FormFieldState<List<PlatformFile>?> field) {
200+
void _setFiles(List<PlatformFile> files, FormFieldState<List<PlatformFile>?> field) {
209201
setState(() => _files = files);
210202
field.didChange(_files);
211203
}
@@ -215,16 +207,14 @@ class _FormBuilderFilePickerState
215207
field.didChange(_files);
216208
}
217209

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

222213
return LayoutBuilder(
223214
builder: (context, constraints) {
224215
const count = 3;
225216
const spacing = 10;
226-
final itemSize =
227-
(constraints.biggest.width - (count * spacing)) / count;
217+
final itemSize = (constraints.biggest.width - (count * spacing)) / count;
228218
return Wrap(
229219
// scrollDirection: Axis.horizontal,
230220
alignment: WrapAlignment.start,
@@ -243,11 +233,10 @@ class _FormBuilderFilePickerState
243233
children: <Widget>[
244234
Container(
245235
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)
251240
: Container(
252241
alignment: Alignment.center,
253242
color: theme.primaryColor,

0 commit comments

Comments
 (0)