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

Commit 9f3c42b

Browse files
author
Juan Angel Dausa
committed
Update file_selector_platform_interface by adding the new property 'uniformTypeIdentifiers' to the XTypeGroup.
1 parent feed66b commit 9f3c42b

File tree

4 files changed

+76
-8
lines changed

4 files changed

+76
-8
lines changed

packages/file_selector/file_selector_platform_interface/CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## NEXT
1+
## 2.2.0
22

3+
* Adds the `uniformTypeIdentifiers` property to the `XTypeGroup` that relies on `macUTIs`. The last will be deprecated for future releases.
34
* Updates minimum Flutter version to 2.10.
45

56
## 2.1.0

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
@@ -12,9 +12,13 @@ class XTypeGroup {
1212
this.label,
1313
List<String>? extensions,
1414
this.mimeTypes,
15-
this.macUTIs,
15+
List<String>? macUTIs,
16+
List<String>? uniformTypeIdentifiers,
1617
this.webWildCards,
17-
}) : extensions = _removeLeadingDots(extensions);
18+
}) : extensions = _removeLeadingDots(extensions),
19+
assert(uniformTypeIdentifiers == null || macUTIs == null,
20+
'It is only allowed to specify either macUTIs or uniformTypeIdentifiers'),
21+
uniformTypeIdentifiers = uniformTypeIdentifiers ?? macUTIs;
1822

1923
/// The 'name' or reference to this group of types
2024
final String? label;
@@ -25,8 +29,8 @@ class XTypeGroup {
2529
/// The MIME types for this group
2630
final List<String>? mimeTypes;
2731

28-
/// The UTIs for this group
29-
final List<String>? macUTIs;
32+
/// The uniform type identifiers for this group
33+
final List<String>? uniformTypeIdentifiers;
3034

3135
/// The web wild cards for this group (ex: image/*, video/*)
3236
final List<String>? webWildCards;
@@ -50,6 +54,9 @@ class XTypeGroup {
5054
(webWildCards?.isEmpty ?? true);
5155
}
5256

57+
/// Returns the list of uniform type identifiers for this group
58+
List<String>? get macUTIs => uniformTypeIdentifiers;
59+
5360
static List<String>? _removeLeadingDots(List<String>? exts) => exts
5461
?.map((String ext) => ext.startsWith('.') ? ext.substring(1) : ext)
5562
.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.1.0
7+
version: 2.2.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

+62-2
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
final List<String> extensions = <String>['txt', 'jpg'];
1312
final List<String> mimeTypes = <String>['text/plain'];
1413
final List<String> macUTIs = <String>['public.plain-text'];
1514
final List<String> webWildCards = <String>['image/*'];
16-
15+
const String label = 'test group';
1716
final XTypeGroup group = XTypeGroup(
1817
label: label,
1918
extensions: extensions,
@@ -71,6 +70,67 @@ void main() {
7170
expect(webOnly.allowsAny, false);
7271
});
7372

73+
test('passing only macUTIs should fill uniformTypeIdentifiers', () {
74+
final List<String> macUTIs = <String>['public.plain-text'];
75+
final XTypeGroup group = XTypeGroup(
76+
macUTIs: macUTIs,
77+
);
78+
79+
expect(group.uniformTypeIdentifiers, macUTIs);
80+
});
81+
82+
test('passing only macUTIs should fill macUTIs', () {
83+
final List<String> macUTIs = <String>['public.plain-text'];
84+
final 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+
final List<String> uniformTypeIdentifiers = <String>['public.plain-text'];
95+
final XTypeGroup group = XTypeGroup(
96+
uniformTypeIdentifiers: uniformTypeIdentifiers,
97+
);
98+
99+
expect(group.uniformTypeIdentifiers, uniformTypeIdentifiers);
100+
});
101+
102+
test('passing only uniformTypeIdentifiers should fill macUTIs', () {
103+
final List<String> uniformTypeIdentifiers = <String>['public.plain-text'];
104+
final XTypeGroup group = XTypeGroup(
105+
uniformTypeIdentifiers: uniformTypeIdentifiers,
106+
);
107+
108+
expect(group.macUTIs, uniformTypeIdentifiers);
109+
});
110+
111+
test('passing uniformTypeIdentifiers and macUTIs should throw', () {
112+
final List<String> macUTIs = <String>['public.plain-text'];
113+
final 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+
final XTypeGroup group = XTypeGroup();
130+
131+
expect(group.uniformTypeIdentifiers, null);
132+
});
133+
74134
test('Leading dots are removed from extensions', () {
75135
final List<String> extensions = <String>['.txt', '.jpg'];
76136
final XTypeGroup group = XTypeGroup(extensions: extensions);

0 commit comments

Comments
 (0)