Skip to content

Commit 7499192

Browse files
[file_selector] Deprecates macUTIs (#3888)
Now that all in-repo consuming code has switch to `uniformTypeIdentifiers`, deprecate `macUTIs` (and minimize internal use of it in this package). Fixes flutter/flutter#103743
1 parent 4b80d4f commit 7499192

File tree

5 files changed

+93
-79
lines changed

5 files changed

+93
-79
lines changed

packages/file_selector/file_selector_platform_interface/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## NEXT
1+
## 2.5.0
22

3+
* Deprecates `macUTIs` in favor of `uniformTypeIdentifiers`.
34
* Aligns Dart and Flutter SDK constraints.
45

56
## 2.4.1

packages/file_selector/file_selector_platform_interface/lib/src/types/x_type_group/x_type_group.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ class XTypeGroup {
1414
this.label,
1515
List<String>? extensions,
1616
this.mimeTypes,
17-
List<String>? macUTIs,
1817
List<String>? uniformTypeIdentifiers,
1918
this.webWildCards,
19+
@Deprecated('Use uniformTypeIdentifiers instead') List<String>? macUTIs,
2020
}) : _extensions = extensions,
2121
assert(uniformTypeIdentifiers == null || macUTIs == null,
2222
'Only one of uniformTypeIdentifiers or macUTIs can be non-null'),
@@ -47,20 +47,25 @@ class XTypeGroup {
4747
'label': label,
4848
'extensions': extensions,
4949
'mimeTypes': mimeTypes,
50-
'macUTIs': macUTIs,
50+
'uniformTypeIdentifiers': uniformTypeIdentifiers,
5151
'webWildCards': webWildCards,
52+
// This is kept for backwards compatibility with anything that was
53+
// relying on it, including implementers of `MethodChannelFileSelector`
54+
// (since toJSON is used in the method channel parameter serialization).
55+
'macUTIs': uniformTypeIdentifiers,
5256
};
5357
}
5458

5559
/// True if this type group should allow any file.
5660
bool get allowsAny {
5761
return (extensions?.isEmpty ?? true) &&
5862
(mimeTypes?.isEmpty ?? true) &&
59-
(macUTIs?.isEmpty ?? true) &&
63+
(uniformTypeIdentifiers?.isEmpty ?? true) &&
6064
(webWildCards?.isEmpty ?? true);
6165
}
6266

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

6671
static List<String>? _removeLeadingDots(List<String>? exts) => exts

packages/file_selector/file_selector_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/file_selector
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+file_selector%22
55
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
66
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
7-
version: 2.4.1
7+
version: 2.5.0
88

99
environment:
1010
sdk: ">=2.17.0 <4.0.0"

packages/file_selector/file_selector_platform_interface/test/method_channel_file_selector_test.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ void main() {
3535
label: 'text',
3636
extensions: <String>['txt'],
3737
mimeTypes: <String>['text/plain'],
38-
macUTIs: <String>['public.text'],
38+
uniformTypeIdentifiers: <String>['public.text'],
3939
);
4040

4141
const XTypeGroup groupTwo = XTypeGroup(
4242
label: 'image',
4343
extensions: <String>['jpg'],
4444
mimeTypes: <String>['image/jpg'],
45-
macUTIs: <String>['public.image'],
45+
uniformTypeIdentifiers: <String>['public.image'],
4646
webWildCards: <String>['image/*']);
4747

4848
await plugin
@@ -97,14 +97,14 @@ void main() {
9797
label: 'text',
9898
extensions: <String>['txt'],
9999
mimeTypes: <String>['text/plain'],
100-
macUTIs: <String>['public.text'],
100+
uniformTypeIdentifiers: <String>['public.text'],
101101
);
102102

103103
const XTypeGroup groupTwo = XTypeGroup(
104104
label: 'image',
105105
extensions: <String>['jpg'],
106106
mimeTypes: <String>['image/jpg'],
107-
macUTIs: <String>['public.image'],
107+
uniformTypeIdentifiers: <String>['public.image'],
108108
webWildCards: <String>['image/*']);
109109

110110
await plugin
@@ -160,14 +160,14 @@ void main() {
160160
label: 'text',
161161
extensions: <String>['txt'],
162162
mimeTypes: <String>['text/plain'],
163-
macUTIs: <String>['public.text'],
163+
uniformTypeIdentifiers: <String>['public.text'],
164164
);
165165

166166
const XTypeGroup groupTwo = XTypeGroup(
167167
label: 'image',
168168
extensions: <String>['jpg'],
169169
mimeTypes: <String>['image/jpg'],
170-
macUTIs: <String>['public.image'],
170+
uniformTypeIdentifiers: <String>['public.image'],
171171
webWildCards: <String>['image/*']);
172172

173173
await plugin

packages/file_selector/file_selector_platform_interface/test/x_type_group_test.dart

Lines changed: 76 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,25 @@ void main() {
1010
test('toJSON() creates correct map', () {
1111
const List<String> extensions = <String>['txt', 'jpg'];
1212
const List<String> mimeTypes = <String>['text/plain'];
13-
const List<String> macUTIs = <String>['public.plain-text'];
13+
const List<String> uniformTypeIdentifiers = <String>['public.plain-text'];
1414
const List<String> webWildCards = <String>['image/*'];
1515
const String label = 'test group';
1616
const XTypeGroup group = XTypeGroup(
1717
label: label,
1818
extensions: extensions,
1919
mimeTypes: mimeTypes,
20-
macUTIs: macUTIs,
20+
uniformTypeIdentifiers: uniformTypeIdentifiers,
2121
webWildCards: webWildCards,
2222
);
2323

2424
final Map<String, dynamic> jsonMap = group.toJSON();
2525
expect(jsonMap['label'], label);
2626
expect(jsonMap['extensions'], extensions);
2727
expect(jsonMap['mimeTypes'], mimeTypes);
28-
expect(jsonMap['macUTIs'], macUTIs);
28+
expect(jsonMap['uniformTypeIdentifiers'], uniformTypeIdentifiers);
2929
expect(jsonMap['webWildCards'], webWildCards);
30+
// Validate the legacy key for backwards compatibility.
31+
expect(jsonMap['macUTIs'], uniformTypeIdentifiers);
3032
});
3133

3234
test('a wildcard group can be created', () {
@@ -37,7 +39,7 @@ void main() {
3739
final Map<String, dynamic> jsonMap = group.toJSON();
3840
expect(jsonMap['extensions'], null);
3941
expect(jsonMap['mimeTypes'], null);
40-
expect(jsonMap['macUTIs'], null);
42+
expect(jsonMap['uniformTypeIdentifiers'], null);
4143
expect(jsonMap['webWildCards'], null);
4244
expect(group.allowsAny, true);
4345
});
@@ -47,7 +49,7 @@ void main() {
4749
label: 'Any',
4850
extensions: <String>[],
4951
mimeTypes: <String>[],
50-
macUTIs: <String>[],
52+
uniformTypeIdentifiers: <String>[],
5153
webWildCards: <String>[],
5254
);
5355

@@ -59,8 +61,8 @@ void main() {
5961
XTypeGroup(label: 'extensions', extensions: <String>['txt']);
6062
const XTypeGroup mimeOnly =
6163
XTypeGroup(label: 'mime', mimeTypes: <String>['text/plain']);
62-
const XTypeGroup utiOnly =
63-
XTypeGroup(label: 'utis', macUTIs: <String>['public.text']);
64+
const XTypeGroup utiOnly = XTypeGroup(
65+
label: 'utis', uniformTypeIdentifiers: <String>['public.text']);
6466
const XTypeGroup webOnly =
6567
XTypeGroup(label: 'web', webWildCards: <String>['.txt']);
6668

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

73-
test('passing only macUTIs should fill uniformTypeIdentifiers', () {
74-
const List<String> macUTIs = <String>['public.plain-text'];
75-
const XTypeGroup group = XTypeGroup(
76-
macUTIs: macUTIs,
77-
);
78-
79-
expect(group.uniformTypeIdentifiers, macUTIs);
80-
});
81-
82-
test(
83-
'passing only uniformTypeIdentifiers should fill uniformTypeIdentifiers',
84-
() {
85-
const List<String> uniformTypeIdentifiers = <String>['public.plain-text'];
86-
const XTypeGroup group = XTypeGroup(
87-
uniformTypeIdentifiers: uniformTypeIdentifiers,
88-
);
89-
90-
expect(group.uniformTypeIdentifiers, uniformTypeIdentifiers);
91-
});
92-
93-
test('macUTIs getter return macUTIs value passed in constructor', () {
94-
const List<String> macUTIs = <String>['public.plain-text'];
95-
const XTypeGroup group = XTypeGroup(
96-
macUTIs: macUTIs,
97-
);
98-
99-
expect(group.macUTIs, macUTIs);
100-
});
101-
102-
test(
103-
'macUTIs getter returns uniformTypeIdentifiers value passed in constructor',
104-
() {
105-
const List<String> uniformTypeIdentifiers = <String>['public.plain-text'];
106-
const XTypeGroup group = XTypeGroup(
107-
uniformTypeIdentifiers: uniformTypeIdentifiers,
108-
);
109-
110-
expect(group.macUTIs, uniformTypeIdentifiers);
111-
});
112-
113-
test('passing both uniformTypeIdentifiers and macUTIs should throw', () {
114-
const List<String> macUTIs = <String>['public.plain-text'];
115-
const List<String> uniformTypeIndentifiers = <String>[
116-
'public.plain-images'
117-
];
118-
expect(
119-
() => XTypeGroup(
120-
macUTIs: macUTIs,
121-
uniformTypeIdentifiers: uniformTypeIndentifiers),
122-
throwsA(predicate((Object? e) =>
123-
e is AssertionError &&
124-
e.message ==
125-
'Only one of uniformTypeIdentifiers or macUTIs can be non-null')));
126-
});
127-
128-
test(
129-
'having uniformTypeIdentifiers and macUTIs as null should leave uniformTypeIdentifiers as null',
130-
() {
131-
const XTypeGroup group = XTypeGroup();
132-
133-
expect(group.uniformTypeIdentifiers, null);
75+
group('macUTIs -> uniformTypeIdentifiers transition', () {
76+
test('passing only macUTIs should fill uniformTypeIdentifiers', () {
77+
const List<String> uniformTypeIdentifiers = <String>[
78+
'public.plain-text'
79+
];
80+
const XTypeGroup group = XTypeGroup(
81+
macUTIs: uniformTypeIdentifiers,
82+
);
83+
84+
expect(group.uniformTypeIdentifiers, uniformTypeIdentifiers);
85+
});
86+
87+
test(
88+
'passing only uniformTypeIdentifiers should fill uniformTypeIdentifiers',
89+
() {
90+
const List<String> uniformTypeIdentifiers = <String>[
91+
'public.plain-text'
92+
];
93+
const XTypeGroup group = XTypeGroup(
94+
uniformTypeIdentifiers: uniformTypeIdentifiers,
95+
);
96+
97+
expect(group.uniformTypeIdentifiers, uniformTypeIdentifiers);
98+
});
99+
100+
test('macUTIs getter return macUTIs value passed in constructor', () {
101+
const List<String> uniformTypeIdentifiers = <String>[
102+
'public.plain-text'
103+
];
104+
const XTypeGroup group = XTypeGroup(
105+
macUTIs: uniformTypeIdentifiers,
106+
);
107+
108+
expect(group.macUTIs, uniformTypeIdentifiers);
109+
});
110+
111+
test(
112+
'macUTIs getter returns uniformTypeIdentifiers value passed in constructor',
113+
() {
114+
const List<String> uniformTypeIdentifiers = <String>[
115+
'public.plain-text'
116+
];
117+
const XTypeGroup group = XTypeGroup(
118+
uniformTypeIdentifiers: uniformTypeIdentifiers,
119+
);
120+
121+
expect(group.macUTIs, uniformTypeIdentifiers);
122+
});
123+
124+
test('passing both uniformTypeIdentifiers and macUTIs should throw', () {
125+
expect(
126+
() => XTypeGroup(
127+
macUTIs: const <String>['public.plain-text'],
128+
uniformTypeIdentifiers: const <String>['public.plain-images']),
129+
throwsA(predicate((Object? e) =>
130+
e is AssertionError &&
131+
e.message ==
132+
'Only one of uniformTypeIdentifiers or macUTIs can be non-null')));
133+
});
134+
135+
test(
136+
'having uniformTypeIdentifiers and macUTIs as null should leave uniformTypeIdentifiers as null',
137+
() {
138+
const XTypeGroup group = XTypeGroup();
139+
140+
expect(group.uniformTypeIdentifiers, null);
141+
});
134142
});
135143

136144
test('leading dots are removed from extensions', () {

0 commit comments

Comments
 (0)