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

Commit 018e25e

Browse files
Juan Angel Dausaeugerossetto
authored andcommitted
Update file_selector_platform_interface by adding the new property 'uniformTypeIdentifiers' to the XTypeGroup.
1 parent 5239062 commit 018e25e

File tree

3 files changed

+79
-8
lines changed

3 files changed

+79
-8
lines changed

packages/file_selector/file_selector_platform_interface/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.3.0
2+
3+
* Adds the `uniformTypeIdentifiers` property to the `XTypeGroup` that relies on `macUTIs`. The last will be deprecated for future releases.
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

Lines changed: 11 additions & 4 deletions
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+
'It is only allowed to specify either macUTIs or uniformTypeIdentifiers'),
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/test/x_type_group_test.dart

Lines changed: 64 additions & 4 deletions
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,68 @@ 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('passing only macUTIs should fill macUTIs', () {
83+
const List<String> macUTIs = <String>['public.plain-text'];
84+
const XTypeGroup group = XTypeGroup(
85+
macUTIs: macUTIs,
86+
);
87+
88+
expect(group.macUTIs, macUTIs);
89+
});
90+
91+
test(
92+
'passing only uniformTypeIdentifiers should fill uniformTypeIdentifiers',
93+
() {
94+
const List<String> uniformTypeIdentifiers = <String>['public.plain-text'];
95+
const XTypeGroup group = XTypeGroup(
96+
uniformTypeIdentifiers: uniformTypeIdentifiers,
97+
);
98+
99+
expect(group.uniformTypeIdentifiers, uniformTypeIdentifiers);
100+
});
101+
102+
test('passing only uniformTypeIdentifiers should fill macUTIs', () {
103+
const List<String> uniformTypeIdentifiers = <String>['public.plain-text'];
104+
const XTypeGroup group = XTypeGroup(
105+
uniformTypeIdentifiers: uniformTypeIdentifiers,
106+
);
107+
108+
expect(group.macUTIs, uniformTypeIdentifiers);
109+
});
110+
111+
test('passing uniformTypeIdentifiers and macUTIs should throw', () {
112+
const List<String> macUTIs = <String>['public.plain-text'];
113+
const List<String> uniformTypeIndentifiers = <String>[
114+
'public.plain-images'
115+
];
116+
expect(
117+
() => XTypeGroup(
118+
macUTIs: macUTIs,
119+
uniformTypeIdentifiers: uniformTypeIndentifiers),
120+
throwsA(predicate((Object? e) =>
121+
e is AssertionError &&
122+
e.message ==
123+
'It is only allowed to specify either macUTIs or uniformTypeIdentifiers')));
124+
});
125+
126+
test(
127+
'having uniformTypeIdentifiers and macUTIs as null should leave uniformTypeIdentifiers as null',
128+
() {
129+
const XTypeGroup group = XTypeGroup();
130+
131+
expect(group.uniformTypeIdentifiers, null);
132+
});
133+
134+
test('leading dots are removed from extensions', () {
75135
const List<String> extensions = <String>['.txt', '.jpg'];
76136
const XTypeGroup group = XTypeGroup(extensions: extensions);
77137

0 commit comments

Comments
 (0)