Skip to content

Commit

Permalink
[file_selector] Add allowsAny to XTypeGroup (flutter#6094)
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartmorgan authored and yutaaraki-toydium committed Aug 12, 2022
1 parent a000b73 commit 8e1fb5f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT
## 2.1.0

* Removes unnecessary imports.
* Adds `allowsAny` to `XTypeGroup` as a simple and future-proof way of identifying
wildcard groups.

## 2.0.4

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ class XTypeGroup {
};
}

/// True if this type group should allow any file.
bool get allowsAny {
return (extensions?.isEmpty ?? true) &&
(mimeTypes?.isEmpty ?? true) &&
(macUTIs?.isEmpty ?? true) &&
(webWildCards?.isEmpty ?? true);
}

static List<String>? _removeLeadingDots(List<String>? exts) => exts
?.map((String ext) => ext.startsWith('.') ? ext.substring(1) : ext)
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/tree/main/packages/file_selector/
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+file_selector%22
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 2.0.4
version: 2.1.0

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,35 @@ void main() {
expect(jsonMap['mimeTypes'], null);
expect(jsonMap['macUTIs'], null);
expect(jsonMap['webWildCards'], null);
expect(group.allowsAny, true);
});

test('allowsAny treats empty arrays the same as null', () {
final XTypeGroup group = XTypeGroup(
label: 'Any',
extensions: <String>[],
mimeTypes: <String>[],
macUTIs: <String>[],
webWildCards: <String>[],
);

expect(group.allowsAny, true);
});

test('allowsAny returns false if anything is set', () {
final XTypeGroup extensionOnly =
XTypeGroup(label: 'extensions', extensions: <String>['txt']);
final XTypeGroup mimeOnly =
XTypeGroup(label: 'mime', mimeTypes: <String>['text/plain']);
final XTypeGroup utiOnly =
XTypeGroup(label: 'utis', macUTIs: <String>['public.text']);
final XTypeGroup webOnly =
XTypeGroup(label: 'web', webWildCards: <String>['.txt']);

expect(extensionOnly.allowsAny, false);
expect(mimeOnly.allowsAny, false);
expect(utiOnly.allowsAny, false);
expect(webOnly.allowsAny, false);
});

test('Leading dots are removed from extensions', () {
Expand Down

0 comments on commit 8e1fb5f

Please sign in to comment.