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

[file_selector] Allow empty type groups #3261

Merged
merged 1 commit into from Nov 11, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,3 +1,7 @@
## 1.0.1

* Allow type groups that allow any file.

## 1.0.0

* Initial release.
Expand Up @@ -5,18 +5,16 @@
/// A set of allowed XTypes
class XTypeGroup {
/// Creates a new group with the given label and file extensions.
///
/// A group with none of the type options provided indicates that any type is
/// allowed.
ditman marked this conversation as resolved.
Show resolved Hide resolved
XTypeGroup({
this.label,
this.extensions,
this.mimeTypes,
this.macUTIs,
this.webWildCards,
}) : assert(
!((extensions == null || extensions.isEmpty) &&
(mimeTypes == null || mimeTypes.isEmpty) &&
(macUTIs == null || macUTIs.isEmpty) &&
(webWildCards == null || webWildCards.isEmpty)),
"At least one type must be provided for an XTypeGroup.");
});

/// The 'name' or reference to this group of types
final String label;
Expand Down
Expand Up @@ -3,7 +3,7 @@ description: A common platform interface for the file_selector plugin.
homepage: https://github.com/flutter/plugins/tree/master/packages/file_selector/file_selector_platform_interface
# 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: 1.0.0
version: 1.0.1

dependencies:
flutter:
Expand Down
Expand Up @@ -7,10 +7,6 @@ import 'package:file_selector_platform_interface/file_selector_platform_interfac

void main() {
group('XTypeGroup', () {
test('fails assertion with no parameters set', () {
expect(() => XTypeGroup(), throwsAssertionError);
});

test('toJSON() creates correct map', () {
final label = 'test group';
final extensions = ['.txt', '.jpg'];
Expand All @@ -33,5 +29,17 @@ void main() {
expect(jsonMap['macUTIs'], macUTIs);
expect(jsonMap['webWildCards'], webWildCards);
});

test('A wildcard group can be created', () {
final group = XTypeGroup(
label: 'Any',
);

final jsonMap = group.toJSON();
expect(jsonMap['extensions'], null);
expect(jsonMap['mimeTypes'], null);
expect(jsonMap['macUTIs'], null);
expect(jsonMap['webWildCards'], null);
});
});
}