Skip to content

Commit 80d6be0

Browse files
Merge pull request #35 from grundid/type_selectors
added description for the new field
2 parents 7f9e0ff + 6393d47 commit 80d6be0

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,50 @@ Since this package makes use of [file_picker package](https://pub.dev/packages/f
3535
),
3636
```
3737

38+
On mobile platforms the file picker will open a default document picker if used with FileType.any.
39+
If you want to be able to pick documents and images in the same form field you will need to define
40+
different file types and thus different selectors. To achieve this use the typeSelectors parameter:
41+
This way the user will see two buttons to open a file picker for documents and a file picker for the photos
42+
gallery.
43+
44+
For example:
45+
46+
```dart
47+
FormBuilderFilePicker(
48+
name: "attachments",
49+
previewImages: false,
50+
allowMultiple: true,
51+
withData: true,
52+
typeSelectors: [
53+
TypeSelector(
54+
type: FileType.any,
55+
selector: Row(
56+
children: <Widget>[
57+
Icon(Icons.add_circle),
58+
Padding(
59+
padding: const EdgeInsets.only(left: 8.0),
60+
child: Text("Add documents"),
61+
),
62+
],
63+
),
64+
),
65+
if (!kIsWeb)
66+
TypeSelector(
67+
type: FileType.image,
68+
selector: Row(
69+
children: <Widget>[
70+
Icon(Icons.add_photo_alternate),
71+
Padding(
72+
padding: const EdgeInsets.only(left: 8.0),
73+
child: Text("Add images"),
74+
),
75+
],
76+
),
77+
),
78+
],
79+
)
80+
```
81+
3882
## Credits
3983

4084
<a href="https://github.com/flutter-form-builder-ecosystem/form_builder_file_picker/graphs/contributors">

lib/src/form_builder_file_picker.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class TypeSelector {
2424
final FileType type;
2525
final Widget selector;
2626

27-
TypeSelector({required this.type, required this.selector});
27+
const TypeSelector({required this.type, required this.selector});
2828
}
2929

3030
/// Field for image(s) from user device storage
@@ -91,8 +91,13 @@ class FormBuilderFilePicker extends FormBuilderField<List<PlatformFile>> {
9191
this.withReadStream = false,
9292
this.allowMultiple = false,
9393
this.previewImages = true,
94-
this.selector = const Icon(Icons.add_circle),
95-
this.type = FileType.any,
94+
@Deprecated("please use typeSelectors for better picker and file type control")
95+
this.selector = const Icon(Icons.add_circle),
96+
@Deprecated("please use typeSelectors for better picker and file type control")
97+
this.type = FileType.any,
98+
// TODO: once the above fields are removed typeSelectors should be made not null and initialized as
99+
// const [TypeSelector(type: FileType.any, selector: Icon(Icons.add_circle))]
100+
// the typeSelectorList variable can be then removed and we can use typeSelectors directly
96101
this.typeSelectors,
97102
this.allowedExtensions,
98103
this.onFileLoading,

0 commit comments

Comments
 (0)