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

[file_selector] Add allowsAny to XTypeGroup #6094

Merged
merged 1 commit into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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