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

Commit fd3ee38

Browse files
authored
[file_selector] Update file_selector_platform_interface by adding the new property 'uniformTypeIdentifiers' to the XTypeGroup. (#6433)
1 parent 5a0209d commit fd3ee38

File tree

4 files changed

+82
-9
lines changed

4 files changed

+82
-9
lines changed

packages/file_selector/file_selector_platform_interface/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.3.0
2+
3+
* Replaces `macUTIs` with `uniformTypeIdentifiers`. `macUTIs` is available as an alias, but will be deprecated in a future release.
4+
15
## 2.2.0
26

37
* Makes `XTypeGroup`'s constructor constant.

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

+11-4
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,22 @@ class XTypeGroup {
1414
this.label,
1515
List<String>? extensions,
1616
this.mimeTypes,
17-
this.macUTIs,
17+
List<String>? macUTIs,
18+
List<String>? uniformTypeIdentifiers,
1819
this.webWildCards,
19-
}) : _extensions = extensions;
20+
}) : _extensions = extensions,
21+
assert(uniformTypeIdentifiers == null || macUTIs == null,
22+
'Only one of uniformTypeIdentifiers or macUTIs can be non-null'),
23+
uniformTypeIdentifiers = uniformTypeIdentifiers ?? macUTIs;
2024

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

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

27-
/// The UTIs for this group.
28-
final List<String>? macUTIs;
31+
/// The uniform type identifiers for this group
32+
final List<String>? uniformTypeIdentifiers;
2933

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

63+
/// Returns the list of uniform type identifiers for this group
64+
List<String>? get macUTIs => uniformTypeIdentifiers;
65+
5966
static List<String>? _removeLeadingDots(List<String>? exts) => exts
6067
?.map((String ext) => ext.startsWith('.') ? ext.substring(1) : ext)
6168
.toList();

packages/file_selector/file_selector_platform_interface/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/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.2.0
7+
version: 2.3.0
88

99
environment:
1010
sdk: ">=2.12.0 <3.0.0"

packages/file_selector/file_selector_platform_interface/test/x_type_group_test.dart

+66-4
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ import 'package:flutter_test/flutter_test.dart';
88
void main() {
99
group('XTypeGroup', () {
1010
test('toJSON() creates correct map', () {
11-
const String label = 'test group';
1211
const List<String> extensions = <String>['txt', 'jpg'];
1312
const List<String> mimeTypes = <String>['text/plain'];
1413
const List<String> macUTIs = <String>['public.plain-text'];
1514
const List<String> webWildCards = <String>['image/*'];
16-
15+
const String label = 'test group';
1716
const XTypeGroup group = XTypeGroup(
1817
label: label,
1918
extensions: extensions,
@@ -30,7 +29,7 @@ void main() {
3029
expect(jsonMap['webWildCards'], webWildCards);
3130
});
3231

33-
test('A wildcard group can be created', () {
32+
test('a wildcard group can be created', () {
3433
const XTypeGroup group = XTypeGroup(
3534
label: 'Any',
3635
);
@@ -71,7 +70,70 @@ void main() {
7170
expect(webOnly.allowsAny, false);
7271
});
7372

74-
test('Leading dots are removed from extensions', () {
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);
134+
});
135+
136+
test('leading dots are removed from extensions', () {
75137
const List<String> extensions = <String>['.txt', '.jpg'];
76138
const XTypeGroup group = XTypeGroup(extensions: extensions);
77139

0 commit comments

Comments
 (0)