From 5fd9f856c403c638eed3e50fc9ed873e68cfa5cd Mon Sep 17 00:00:00 2001 From: Juan Angel Dausa Date: Thu, 15 Sep 2022 16:56:48 -0300 Subject: [PATCH 1/4] Update file_selector_platform_interface by adding the new property 'uniformTypeIdentifiers' to the XTypeGroup. --- .../CHANGELOG.md | 4 ++ .../src/types/x_type_group/x_type_group.dart | 15 ++-- .../test/x_type_group_test.dart | 68 +++++++++++++++++-- 3 files changed, 79 insertions(+), 8 deletions(-) diff --git a/packages/file_selector/file_selector_platform_interface/CHANGELOG.md b/packages/file_selector/file_selector_platform_interface/CHANGELOG.md index ad1fe2cb6cef..b42fc5458a30 100644 --- a/packages/file_selector/file_selector_platform_interface/CHANGELOG.md +++ b/packages/file_selector/file_selector_platform_interface/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.3.0 + +* Adds the `uniformTypeIdentifiers` property to the `XTypeGroup` that relies on `macUTIs`. The last will be deprecated for future releases. + ## 2.2.0 * Makes `XTypeGroup`'s constructor constant. diff --git a/packages/file_selector/file_selector_platform_interface/lib/src/types/x_type_group/x_type_group.dart b/packages/file_selector/file_selector_platform_interface/lib/src/types/x_type_group/x_type_group.dart index 00cd56563c32..cf020f20dfde 100644 --- a/packages/file_selector/file_selector_platform_interface/lib/src/types/x_type_group/x_type_group.dart +++ b/packages/file_selector/file_selector_platform_interface/lib/src/types/x_type_group/x_type_group.dart @@ -14,9 +14,13 @@ class XTypeGroup { this.label, List? extensions, this.mimeTypes, - this.macUTIs, + List? macUTIs, + List? uniformTypeIdentifiers, this.webWildCards, - }) : _extensions = extensions; + }) : _extensions = extensions, + assert(uniformTypeIdentifiers == null || macUTIs == null, + 'It is only allowed to specify either macUTIs or uniformTypeIdentifiers'), + uniformTypeIdentifiers = uniformTypeIdentifiers ?? macUTIs; /// The 'name' or reference to this group of types. final String? label; @@ -24,8 +28,8 @@ class XTypeGroup { /// The MIME types for this group. final List? mimeTypes; - /// The UTIs for this group. - final List? macUTIs; + /// The uniform type identifiers for this group + final List? uniformTypeIdentifiers; /// The web wild cards for this group (ex: image/*, video/*). final List? webWildCards; @@ -56,6 +60,9 @@ class XTypeGroup { (webWildCards?.isEmpty ?? true); } + /// Returns the list of uniform type identifiers for this group + List? get macUTIs => uniformTypeIdentifiers; + static List? _removeLeadingDots(List? exts) => exts ?.map((String ext) => ext.startsWith('.') ? ext.substring(1) : ext) .toList(); diff --git a/packages/file_selector/file_selector_platform_interface/test/x_type_group_test.dart b/packages/file_selector/file_selector_platform_interface/test/x_type_group_test.dart index c5e65d0264f5..61f103ee686b 100644 --- a/packages/file_selector/file_selector_platform_interface/test/x_type_group_test.dart +++ b/packages/file_selector/file_selector_platform_interface/test/x_type_group_test.dart @@ -8,12 +8,11 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group('XTypeGroup', () { test('toJSON() creates correct map', () { - const String label = 'test group'; const List extensions = ['txt', 'jpg']; const List mimeTypes = ['text/plain']; const List macUTIs = ['public.plain-text']; const List webWildCards = ['image/*']; - + const String label = 'test group'; const XTypeGroup group = XTypeGroup( label: label, extensions: extensions, @@ -30,7 +29,7 @@ void main() { expect(jsonMap['webWildCards'], webWildCards); }); - test('A wildcard group can be created', () { + test('a wildcard group can be created', () { const XTypeGroup group = XTypeGroup( label: 'Any', ); @@ -71,7 +70,68 @@ void main() { expect(webOnly.allowsAny, false); }); - test('Leading dots are removed from extensions', () { + test('passing only macUTIs should fill uniformTypeIdentifiers', () { + const List macUTIs = ['public.plain-text']; + const XTypeGroup group = XTypeGroup( + macUTIs: macUTIs, + ); + + expect(group.uniformTypeIdentifiers, macUTIs); + }); + + test('passing only macUTIs should fill macUTIs', () { + const List macUTIs = ['public.plain-text']; + const XTypeGroup group = XTypeGroup( + macUTIs: macUTIs, + ); + + expect(group.macUTIs, macUTIs); + }); + + test( + 'passing only uniformTypeIdentifiers should fill uniformTypeIdentifiers', + () { + const List uniformTypeIdentifiers = ['public.plain-text']; + const XTypeGroup group = XTypeGroup( + uniformTypeIdentifiers: uniformTypeIdentifiers, + ); + + expect(group.uniformTypeIdentifiers, uniformTypeIdentifiers); + }); + + test('passing only uniformTypeIdentifiers should fill macUTIs', () { + const List uniformTypeIdentifiers = ['public.plain-text']; + const XTypeGroup group = XTypeGroup( + uniformTypeIdentifiers: uniformTypeIdentifiers, + ); + + expect(group.macUTIs, uniformTypeIdentifiers); + }); + + test('passing uniformTypeIdentifiers and macUTIs should throw', () { + const List macUTIs = ['public.plain-text']; + const List uniformTypeIndentifiers = [ + 'public.plain-images' + ]; + expect( + () => XTypeGroup( + macUTIs: macUTIs, + uniformTypeIdentifiers: uniformTypeIndentifiers), + throwsA(predicate((Object? e) => + e is AssertionError && + e.message == + 'It is only allowed to specify either macUTIs or uniformTypeIdentifiers'))); + }); + + 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', () { const List extensions = ['.txt', '.jpg']; const XTypeGroup group = XTypeGroup(extensions: extensions); From 6f997f05fe8c24886aff6200a9d4dcb710562531 Mon Sep 17 00:00:00 2001 From: eugerossetto Date: Tue, 11 Oct 2022 10:27:59 -0300 Subject: [PATCH 2/4] Version pump --- .../file_selector/file_selector_platform_interface/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/file_selector/file_selector_platform_interface/pubspec.yaml b/packages/file_selector/file_selector_platform_interface/pubspec.yaml index c4500061a3a1..ac8727c09e36 100644 --- a/packages/file_selector/file_selector_platform_interface/pubspec.yaml +++ b/packages/file_selector/file_selector_platform_interface/pubspec.yaml @@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/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.2.0 +version: 2.3.0 environment: sdk: ">=2.12.0 <3.0.0" From 4810d528922c0878938bc874c8d62adb38e87503 Mon Sep 17 00:00:00 2001 From: Alejandro Pinola Date: Tue, 11 Oct 2022 13:02:46 -0300 Subject: [PATCH 3/4] change test description --- .../test/x_type_group_test.dart | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/file_selector/file_selector_platform_interface/test/x_type_group_test.dart b/packages/file_selector/file_selector_platform_interface/test/x_type_group_test.dart index 61f103ee686b..9d4c4c710146 100644 --- a/packages/file_selector/file_selector_platform_interface/test/x_type_group_test.dart +++ b/packages/file_selector/file_selector_platform_interface/test/x_type_group_test.dart @@ -79,15 +79,6 @@ void main() { expect(group.uniformTypeIdentifiers, macUTIs); }); - test('passing only macUTIs should fill macUTIs', () { - const List macUTIs = ['public.plain-text']; - const XTypeGroup group = XTypeGroup( - macUTIs: macUTIs, - ); - - expect(group.macUTIs, macUTIs); - }); - test( 'passing only uniformTypeIdentifiers should fill uniformTypeIdentifiers', () { @@ -99,7 +90,16 @@ void main() { expect(group.uniformTypeIdentifiers, uniformTypeIdentifiers); }); - test('passing only uniformTypeIdentifiers should fill macUTIs', () { + test('macUTIs getter return macUTIs value passed in constructor', () { + const List macUTIs = ['public.plain-text']; + const XTypeGroup group = XTypeGroup( + macUTIs: macUTIs, + ); + + expect(group.macUTIs, macUTIs); + }); + + test('macUTIs getter returns uniformTypeIdentifiers value passed in constructor', () { const List uniformTypeIdentifiers = ['public.plain-text']; const XTypeGroup group = XTypeGroup( uniformTypeIdentifiers: uniformTypeIdentifiers, @@ -108,7 +108,7 @@ void main() { expect(group.macUTIs, uniformTypeIdentifiers); }); - test('passing uniformTypeIdentifiers and macUTIs should throw', () { + test('passing both uniformTypeIdentifiers and macUTIs should throw', () { const List macUTIs = ['public.plain-text']; const List uniformTypeIndentifiers = [ 'public.plain-images' From 875851ceeca4b86b02c6e5ef7364c8a00e06d848 Mon Sep 17 00:00:00 2001 From: Alejandro Pinola Date: Tue, 11 Oct 2022 14:49:14 -0300 Subject: [PATCH 4/4] apply feedback --- .../file_selector_platform_interface/CHANGELOG.md | 2 +- .../lib/src/types/x_type_group/x_type_group.dart | 2 +- .../test/x_type_group_test.dart | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/file_selector/file_selector_platform_interface/CHANGELOG.md b/packages/file_selector/file_selector_platform_interface/CHANGELOG.md index b42fc5458a30..ad803fb12e66 100644 --- a/packages/file_selector/file_selector_platform_interface/CHANGELOG.md +++ b/packages/file_selector/file_selector_platform_interface/CHANGELOG.md @@ -1,6 +1,6 @@ ## 2.3.0 -* Adds the `uniformTypeIdentifiers` property to the `XTypeGroup` that relies on `macUTIs`. The last will be deprecated for future releases. +* Replaces `macUTIs` with `uniformTypeIdentifiers`. `macUTIs` is available as an alias, but will be deprecated in a future release. ## 2.2.0 diff --git a/packages/file_selector/file_selector_platform_interface/lib/src/types/x_type_group/x_type_group.dart b/packages/file_selector/file_selector_platform_interface/lib/src/types/x_type_group/x_type_group.dart index cf020f20dfde..e12b431d91d8 100644 --- a/packages/file_selector/file_selector_platform_interface/lib/src/types/x_type_group/x_type_group.dart +++ b/packages/file_selector/file_selector_platform_interface/lib/src/types/x_type_group/x_type_group.dart @@ -19,7 +19,7 @@ class XTypeGroup { this.webWildCards, }) : _extensions = extensions, assert(uniformTypeIdentifiers == null || macUTIs == null, - 'It is only allowed to specify either macUTIs or uniformTypeIdentifiers'), + 'Only one of uniformTypeIdentifiers or macUTIs can be non-null'), uniformTypeIdentifiers = uniformTypeIdentifiers ?? macUTIs; /// The 'name' or reference to this group of types. diff --git a/packages/file_selector/file_selector_platform_interface/test/x_type_group_test.dart b/packages/file_selector/file_selector_platform_interface/test/x_type_group_test.dart index 9d4c4c710146..5ac5722716c7 100644 --- a/packages/file_selector/file_selector_platform_interface/test/x_type_group_test.dart +++ b/packages/file_selector/file_selector_platform_interface/test/x_type_group_test.dart @@ -99,7 +99,9 @@ void main() { expect(group.macUTIs, macUTIs); }); - test('macUTIs getter returns uniformTypeIdentifiers value passed in constructor', () { + test( + 'macUTIs getter returns uniformTypeIdentifiers value passed in constructor', + () { const List uniformTypeIdentifiers = ['public.plain-text']; const XTypeGroup group = XTypeGroup( uniformTypeIdentifiers: uniformTypeIdentifiers, @@ -120,7 +122,7 @@ void main() { throwsA(predicate((Object? e) => e is AssertionError && e.message == - 'It is only allowed to specify either macUTIs or uniformTypeIdentifiers'))); + 'Only one of uniformTypeIdentifiers or macUTIs can be non-null'))); }); test(