Skip to content

[file_selector] Deprecates macUTIs #3888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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,5 +1,6 @@
## NEXT
## 2.5.0

* Deprecates `macUTIs` in favor of `uniformTypeIdentifiers`.
* Aligns Dart and Flutter SDK constraints.

## 2.4.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class XTypeGroup {
this.label,
List<String>? extensions,
this.mimeTypes,
List<String>? macUTIs,
List<String>? uniformTypeIdentifiers,
this.webWildCards,
@Deprecated('Use uniformTypeIdentifiers instead') List<String>? macUTIs,
}) : _extensions = extensions,
assert(uniformTypeIdentifiers == null || macUTIs == null,
'Only one of uniformTypeIdentifiers or macUTIs can be non-null'),
Expand Down Expand Up @@ -47,20 +47,25 @@ class XTypeGroup {
'label': label,
'extensions': extensions,
'mimeTypes': mimeTypes,
'macUTIs': macUTIs,
'uniformTypeIdentifiers': uniformTypeIdentifiers,
'webWildCards': webWildCards,
// This is kept for backwards compatibility with anything that was
// relying on it, including implementers of `MethodChannelFileSelector`
// (since toJSON is used in the method channel parameter serialization).
'macUTIs': uniformTypeIdentifiers,
};
}

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

/// Returns the list of uniform type identifiers for this group
@Deprecated('Use uniformTypeIdentifiers instead')
List<String>? get macUTIs => uniformTypeIdentifiers;

static List<String>? _removeLeadingDots(List<String>? exts) => exts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/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.4.1
version: 2.5.0

environment:
sdk: ">=2.17.0 <4.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ void main() {
label: 'text',
extensions: <String>['txt'],
mimeTypes: <String>['text/plain'],
macUTIs: <String>['public.text'],
uniformTypeIdentifiers: <String>['public.text'],
);

const XTypeGroup groupTwo = XTypeGroup(
label: 'image',
extensions: <String>['jpg'],
mimeTypes: <String>['image/jpg'],
macUTIs: <String>['public.image'],
uniformTypeIdentifiers: <String>['public.image'],
webWildCards: <String>['image/*']);

await plugin
Expand Down Expand Up @@ -97,14 +97,14 @@ void main() {
label: 'text',
extensions: <String>['txt'],
mimeTypes: <String>['text/plain'],
macUTIs: <String>['public.text'],
uniformTypeIdentifiers: <String>['public.text'],
);

const XTypeGroup groupTwo = XTypeGroup(
label: 'image',
extensions: <String>['jpg'],
mimeTypes: <String>['image/jpg'],
macUTIs: <String>['public.image'],
uniformTypeIdentifiers: <String>['public.image'],
webWildCards: <String>['image/*']);

await plugin
Expand Down Expand Up @@ -160,14 +160,14 @@ void main() {
label: 'text',
extensions: <String>['txt'],
mimeTypes: <String>['text/plain'],
macUTIs: <String>['public.text'],
uniformTypeIdentifiers: <String>['public.text'],
);

const XTypeGroup groupTwo = XTypeGroup(
label: 'image',
extensions: <String>['jpg'],
mimeTypes: <String>['image/jpg'],
macUTIs: <String>['public.image'],
uniformTypeIdentifiers: <String>['public.image'],
webWildCards: <String>['image/*']);

await plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,25 @@ void main() {
test('toJSON() creates correct map', () {
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> uniformTypeIdentifiers = <String>['public.plain-text'];
const List<String> webWildCards = <String>['image/*'];
const String label = 'test group';
const XTypeGroup group = XTypeGroup(
label: label,
extensions: extensions,
mimeTypes: mimeTypes,
macUTIs: macUTIs,
uniformTypeIdentifiers: uniformTypeIdentifiers,
webWildCards: webWildCards,
);

final Map<String, dynamic> jsonMap = group.toJSON();
expect(jsonMap['label'], label);
expect(jsonMap['extensions'], extensions);
expect(jsonMap['mimeTypes'], mimeTypes);
expect(jsonMap['macUTIs'], macUTIs);
expect(jsonMap['uniformTypeIdentifiers'], uniformTypeIdentifiers);
expect(jsonMap['webWildCards'], webWildCards);
// Validate the legacy key for backwards compatibility.
expect(jsonMap['macUTIs'], uniformTypeIdentifiers);
});

test('a wildcard group can be created', () {
Expand All @@ -37,7 +39,7 @@ void main() {
final Map<String, dynamic> jsonMap = group.toJSON();
expect(jsonMap['extensions'], null);
expect(jsonMap['mimeTypes'], null);
expect(jsonMap['macUTIs'], null);
expect(jsonMap['uniformTypeIdentifiers'], null);
expect(jsonMap['webWildCards'], null);
expect(group.allowsAny, true);
});
Expand All @@ -47,7 +49,7 @@ void main() {
label: 'Any',
extensions: <String>[],
mimeTypes: <String>[],
macUTIs: <String>[],
uniformTypeIdentifiers: <String>[],
webWildCards: <String>[],
);

Expand All @@ -59,8 +61,8 @@ void main() {
XTypeGroup(label: 'extensions', extensions: <String>['txt']);
const XTypeGroup mimeOnly =
XTypeGroup(label: 'mime', mimeTypes: <String>['text/plain']);
const XTypeGroup utiOnly =
XTypeGroup(label: 'utis', macUTIs: <String>['public.text']);
const XTypeGroup utiOnly = XTypeGroup(
label: 'utis', uniformTypeIdentifiers: <String>['public.text']);
const XTypeGroup webOnly =
XTypeGroup(label: 'web', webWildCards: <String>['.txt']);

Expand All @@ -70,67 +72,73 @@ void main() {
expect(webOnly.allowsAny, false);
});

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')));
});

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

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

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

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> uniformTypeIdentifiers = <String>[
'public.plain-text'
];
const XTypeGroup group = XTypeGroup(
macUTIs: uniformTypeIdentifiers,
);

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

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', () {
expect(
() => XTypeGroup(
macUTIs: const <String>['public.plain-text'],
uniformTypeIdentifiers: const <String>['public.plain-images']),
throwsA(predicate((Object? e) =>
e is AssertionError &&
e.message ==
'Only one of uniformTypeIdentifiers or macUTIs can be non-null')));
});

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', () {
Expand Down