Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
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,3 +1,7 @@
## 2.3.0

* Replaces `macUTIs` with `uniformTypeIdentifiers`. `macUTIs` is available as an alias, but will be deprecated in a future release.

## 2.2.0

* Makes `XTypeGroup`'s constructor constant.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,22 @@ class XTypeGroup {
this.label,
List<String>? extensions,
this.mimeTypes,
this.macUTIs,
List<String>? macUTIs,
List<String>? uniformTypeIdentifiers,
this.webWildCards,
}) : _extensions = extensions;
}) : _extensions = extensions,
assert(uniformTypeIdentifiers == null || macUTIs == null,
'Only one of uniformTypeIdentifiers or macUTIs can be non-null'),
uniformTypeIdentifiers = uniformTypeIdentifiers ?? macUTIs;

/// The 'name' or reference to this group of types.
final String? label;

/// The MIME types for this group.
final List<String>? mimeTypes;

/// The UTIs for this group.
final List<String>? macUTIs;
/// The uniform type identifiers for this group
final List<String>? uniformTypeIdentifiers;

/// The web wild cards for this group (ex: image/*, video/*).
final List<String>? webWildCards;
Expand Down Expand Up @@ -56,6 +60,9 @@ class XTypeGroup {
(webWildCards?.isEmpty ?? true);
}

/// Returns the list of uniform type identifiers for this group
List<String>? get macUTIs => uniformTypeIdentifiers;

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.2.0
version: 2.3.0

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
group('XTypeGroup', () {
test('toJSON() creates correct map', () {
const String label = 'test group';
const List<String> extensions = <String>['txt', 'jpg'];
const List<String> mimeTypes = <String>['text/plain'];
const List<String> macUTIs = <String>['public.plain-text'];
const List<String> webWildCards = <String>['image/*'];

const String label = 'test group';
const XTypeGroup group = XTypeGroup(
label: label,
extensions: extensions,
Expand All @@ -30,7 +29,7 @@ void main() {
expect(jsonMap['webWildCards'], webWildCards);
});

test('A wildcard group can be created', () {
test('a wildcard group can be created', () {
const XTypeGroup group = XTypeGroup(
label: 'Any',
);
Expand Down Expand Up @@ -71,7 +70,70 @@ void main() {
expect(webOnly.allowsAny, false);
});

test('Leading dots are removed from extensions', () {
test('passing only macUTIs should fill uniformTypeIdentifiers', () {
const List<String> macUTIs = <String>['public.plain-text'];
const XTypeGroup group = XTypeGroup(
macUTIs: macUTIs,
);

expect(group.uniformTypeIdentifiers, macUTIs);
});

test(
'passing only uniformTypeIdentifiers should fill uniformTypeIdentifiers',
() {
const List<String> uniformTypeIdentifiers = <String>['public.plain-text'];
const XTypeGroup group = XTypeGroup(
uniformTypeIdentifiers: uniformTypeIdentifiers,
);

expect(group.uniformTypeIdentifiers, uniformTypeIdentifiers);
});

test('macUTIs getter return macUTIs value passed in constructor', () {
const List<String> macUTIs = <String>['public.plain-text'];
const XTypeGroup group = XTypeGroup(
macUTIs: macUTIs,
);

expect(group.macUTIs, macUTIs);
});

test(
'macUTIs getter returns uniformTypeIdentifiers value passed in constructor',
() {
const List<String> uniformTypeIdentifiers = <String>['public.plain-text'];
const XTypeGroup group = XTypeGroup(
uniformTypeIdentifiers: uniformTypeIdentifiers,
);

expect(group.macUTIs, uniformTypeIdentifiers);
});

test('passing both uniformTypeIdentifiers and macUTIs should throw', () {
const List<String> macUTIs = <String>['public.plain-text'];
const List<String> uniformTypeIndentifiers = <String>[
'public.plain-images'
];
expect(
() => XTypeGroup(
macUTIs: macUTIs,
uniformTypeIdentifiers: uniformTypeIndentifiers),
throwsA(predicate((Object? e) =>
e is AssertionError &&
e.message ==
'Only one of uniformTypeIdentifiers or macUTIs can be non-null')));
Comment on lines +122 to +125
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of asserting the text of the assertion error, I'd just do a expect(closure, throwsAssertionError) (or throwsA(isA<AssertionError>()))

});

test(
'having uniformTypeIdentifiers and macUTIs as null should leave uniformTypeIdentifiers as null',
() {
const XTypeGroup group = XTypeGroup();

expect(group.uniformTypeIdentifiers, null);
});

test('leading dots are removed from extensions', () {
const List<String> extensions = <String>['.txt', '.jpg'];
const XTypeGroup group = XTypeGroup(extensions: extensions);

Expand Down