Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 06530f9

Browse files
[file_selector] Allow empty type groups (#3261)
This was restricted under the assumption that there was no reason for an empty group to exist, but that's not actually true; on platforms with selectable groups in the native UI, it may be useful to provide specific options as well as a fallback option (e.g., "Text files" and "All files").
1 parent 97d36e7 commit 06530f9

4 files changed

Lines changed: 21 additions & 11 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.1
2+
3+
* Allow type groups that allow any file.
4+
15
## 1.0.0
26

37
* Initial release.

packages/file_selector/file_selector_platform_interface/lib/src/types/x_type_group/x_type_group.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,16 @@
55
/// A set of allowed XTypes
66
class XTypeGroup {
77
/// Creates a new group with the given label and file extensions.
8+
///
9+
/// A group with none of the type options provided indicates that any type is
10+
/// allowed.
811
XTypeGroup({
912
this.label,
1013
this.extensions,
1114
this.mimeTypes,
1215
this.macUTIs,
1316
this.webWildCards,
14-
}) : assert(
15-
!((extensions == null || extensions.isEmpty) &&
16-
(mimeTypes == null || mimeTypes.isEmpty) &&
17-
(macUTIs == null || macUTIs.isEmpty) &&
18-
(webWildCards == null || webWildCards.isEmpty)),
19-
"At least one type must be provided for an XTypeGroup.");
17+
});
2018

2119
/// The 'name' or reference to this group of types
2220
final String label;

packages/file_selector/file_selector_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: A common platform interface for the file_selector plugin.
33
homepage: https://github.com/flutter/plugins/tree/master/packages/file_selector/file_selector_platform_interface
44
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
55
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
6-
version: 1.0.0
6+
version: 1.0.1
77

88
dependencies:
99
flutter:

packages/file_selector/file_selector_platform_interface/test/x_type_group_test.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ import 'package:file_selector_platform_interface/file_selector_platform_interfac
77

88
void main() {
99
group('XTypeGroup', () {
10-
test('fails assertion with no parameters set', () {
11-
expect(() => XTypeGroup(), throwsAssertionError);
12-
});
13-
1410
test('toJSON() creates correct map', () {
1511
final label = 'test group';
1612
final extensions = ['.txt', '.jpg'];
@@ -33,5 +29,17 @@ void main() {
3329
expect(jsonMap['macUTIs'], macUTIs);
3430
expect(jsonMap['webWildCards'], webWildCards);
3531
});
32+
33+
test('A wildcard group can be created', () {
34+
final group = XTypeGroup(
35+
label: 'Any',
36+
);
37+
38+
final jsonMap = group.toJSON();
39+
expect(jsonMap['extensions'], null);
40+
expect(jsonMap['mimeTypes'], null);
41+
expect(jsonMap['macUTIs'], null);
42+
expect(jsonMap['webWildCards'], null);
43+
});
3644
});
3745
}

0 commit comments

Comments
 (0)