diff --git a/packages/file_selector/file_selector_platform_interface/CHANGELOG.md b/packages/file_selector/file_selector_platform_interface/CHANGELOG.md index b66fa72df03..756e8ccf94c 100644 --- a/packages/file_selector/file_selector_platform_interface/CHANGELOG.md +++ b/packages/file_selector/file_selector_platform_interface/CHANGELOG.md @@ -1,5 +1,6 @@ -## NEXT +## 2.5.0 +* Deprecates `macUTIs` in favor of `uniformTypeIdentifiers`. * Aligns Dart and Flutter SDK constraints. ## 2.4.1 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 e12b431d91d..0a556b3a2f0 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,9 @@ class XTypeGroup { this.label, List? extensions, this.mimeTypes, - List? macUTIs, List? uniformTypeIdentifiers, this.webWildCards, + @Deprecated('Use uniformTypeIdentifiers instead') List? macUTIs, }) : _extensions = extensions, assert(uniformTypeIdentifiers == null || macUTIs == null, 'Only one of uniformTypeIdentifiers or macUTIs can be non-null'), @@ -47,8 +47,12 @@ class XTypeGroup { 'label': label, 'extensions': extensions, 'mimeTypes': mimeTypes, - 'macUTIs': macUTIs, + 'uniformTypeIdentifiers': uniformTypeIdentifiers, 'webWildCards': webWildCards, + // This is kept for backwards compatibility with anything that was + // relying on it, including implementers of `MethodChannelFileSelector` + // (since toJSON is used in the method channel parameter serialization). + 'macUTIs': uniformTypeIdentifiers, }; } @@ -56,11 +60,12 @@ class XTypeGroup { bool get allowsAny { return (extensions?.isEmpty ?? true) && (mimeTypes?.isEmpty ?? true) && - (macUTIs?.isEmpty ?? true) && + (uniformTypeIdentifiers?.isEmpty ?? true) && (webWildCards?.isEmpty ?? true); } /// Returns the list of uniform type identifiers for this group + @Deprecated('Use uniformTypeIdentifiers instead') List? get macUTIs => uniformTypeIdentifiers; static List? _removeLeadingDots(List? exts) => exts diff --git a/packages/file_selector/file_selector_platform_interface/pubspec.yaml b/packages/file_selector/file_selector_platform_interface/pubspec.yaml index a376719cf06..c0ecf524fb2 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/packages/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.4.1 +version: 2.5.0 environment: sdk: ">=2.17.0 <4.0.0" diff --git a/packages/file_selector/file_selector_platform_interface/test/method_channel_file_selector_test.dart b/packages/file_selector/file_selector_platform_interface/test/method_channel_file_selector_test.dart index c5438f7ecbc..2c7d455dd4d 100644 --- a/packages/file_selector/file_selector_platform_interface/test/method_channel_file_selector_test.dart +++ b/packages/file_selector/file_selector_platform_interface/test/method_channel_file_selector_test.dart @@ -35,14 +35,14 @@ void main() { label: 'text', extensions: ['txt'], mimeTypes: ['text/plain'], - macUTIs: ['public.text'], + uniformTypeIdentifiers: ['public.text'], ); const XTypeGroup groupTwo = XTypeGroup( label: 'image', extensions: ['jpg'], mimeTypes: ['image/jpg'], - macUTIs: ['public.image'], + uniformTypeIdentifiers: ['public.image'], webWildCards: ['image/*']); await plugin @@ -97,14 +97,14 @@ void main() { label: 'text', extensions: ['txt'], mimeTypes: ['text/plain'], - macUTIs: ['public.text'], + uniformTypeIdentifiers: ['public.text'], ); const XTypeGroup groupTwo = XTypeGroup( label: 'image', extensions: ['jpg'], mimeTypes: ['image/jpg'], - macUTIs: ['public.image'], + uniformTypeIdentifiers: ['public.image'], webWildCards: ['image/*']); await plugin @@ -160,14 +160,14 @@ void main() { label: 'text', extensions: ['txt'], mimeTypes: ['text/plain'], - macUTIs: ['public.text'], + uniformTypeIdentifiers: ['public.text'], ); const XTypeGroup groupTwo = XTypeGroup( label: 'image', extensions: ['jpg'], mimeTypes: ['image/jpg'], - macUTIs: ['public.image'], + uniformTypeIdentifiers: ['public.image'], webWildCards: ['image/*']); await plugin 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 5ac5722716c..0a36c82be9b 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 @@ -10,14 +10,14 @@ void main() { test('toJSON() creates correct map', () { const List extensions = ['txt', 'jpg']; const List mimeTypes = ['text/plain']; - const List macUTIs = ['public.plain-text']; + const List uniformTypeIdentifiers = ['public.plain-text']; const List webWildCards = ['image/*']; const String label = 'test group'; const XTypeGroup group = XTypeGroup( label: label, extensions: extensions, mimeTypes: mimeTypes, - macUTIs: macUTIs, + uniformTypeIdentifiers: uniformTypeIdentifiers, webWildCards: webWildCards, ); @@ -25,8 +25,10 @@ void main() { expect(jsonMap['label'], label); expect(jsonMap['extensions'], extensions); expect(jsonMap['mimeTypes'], mimeTypes); - expect(jsonMap['macUTIs'], macUTIs); + expect(jsonMap['uniformTypeIdentifiers'], uniformTypeIdentifiers); expect(jsonMap['webWildCards'], webWildCards); + // Validate the legacy key for backwards compatibility. + expect(jsonMap['macUTIs'], uniformTypeIdentifiers); }); test('a wildcard group can be created', () { @@ -37,7 +39,7 @@ void main() { final Map jsonMap = group.toJSON(); expect(jsonMap['extensions'], null); expect(jsonMap['mimeTypes'], null); - expect(jsonMap['macUTIs'], null); + expect(jsonMap['uniformTypeIdentifiers'], null); expect(jsonMap['webWildCards'], null); expect(group.allowsAny, true); }); @@ -47,7 +49,7 @@ void main() { label: 'Any', extensions: [], mimeTypes: [], - macUTIs: [], + uniformTypeIdentifiers: [], webWildCards: [], ); @@ -59,8 +61,8 @@ void main() { XTypeGroup(label: 'extensions', extensions: ['txt']); const XTypeGroup mimeOnly = XTypeGroup(label: 'mime', mimeTypes: ['text/plain']); - const XTypeGroup utiOnly = - XTypeGroup(label: 'utis', macUTIs: ['public.text']); + const XTypeGroup utiOnly = XTypeGroup( + label: 'utis', uniformTypeIdentifiers: ['public.text']); const XTypeGroup webOnly = XTypeGroup(label: 'web', webWildCards: ['.txt']); @@ -70,67 +72,73 @@ void main() { expect(webOnly.allowsAny, false); }); - 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 uniformTypeIdentifiers should fill uniformTypeIdentifiers', - () { - const List uniformTypeIdentifiers = ['public.plain-text']; - const XTypeGroup group = XTypeGroup( - uniformTypeIdentifiers: uniformTypeIdentifiers, - ); - - expect(group.uniformTypeIdentifiers, uniformTypeIdentifiers); - }); - - 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, - ); - - expect(group.macUTIs, uniformTypeIdentifiers); - }); - - test('passing both 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 == - 'Only one of uniformTypeIdentifiers or macUTIs can be non-null'))); - }); - - test( - 'having uniformTypeIdentifiers and macUTIs as null should leave uniformTypeIdentifiers as null', - () { - const XTypeGroup group = XTypeGroup(); - - expect(group.uniformTypeIdentifiers, null); + group('macUTIs -> uniformTypeIdentifiers transition', () { + test('passing only macUTIs should fill uniformTypeIdentifiers', () { + const List uniformTypeIdentifiers = [ + 'public.plain-text' + ]; + const XTypeGroup group = XTypeGroup( + macUTIs: uniformTypeIdentifiers, + ); + + expect(group.uniformTypeIdentifiers, uniformTypeIdentifiers); + }); + + test( + 'passing only uniformTypeIdentifiers should fill uniformTypeIdentifiers', + () { + const List uniformTypeIdentifiers = [ + 'public.plain-text' + ]; + const XTypeGroup group = XTypeGroup( + uniformTypeIdentifiers: uniformTypeIdentifiers, + ); + + expect(group.uniformTypeIdentifiers, uniformTypeIdentifiers); + }); + + test('macUTIs getter return macUTIs value passed in constructor', () { + const List uniformTypeIdentifiers = [ + 'public.plain-text' + ]; + const XTypeGroup group = XTypeGroup( + macUTIs: uniformTypeIdentifiers, + ); + + expect(group.macUTIs, uniformTypeIdentifiers); + }); + + test( + 'macUTIs getter returns uniformTypeIdentifiers value passed in constructor', + () { + const List uniformTypeIdentifiers = [ + 'public.plain-text' + ]; + const XTypeGroup group = XTypeGroup( + uniformTypeIdentifiers: uniformTypeIdentifiers, + ); + + expect(group.macUTIs, uniformTypeIdentifiers); + }); + + test('passing both uniformTypeIdentifiers and macUTIs should throw', () { + expect( + () => XTypeGroup( + macUTIs: const ['public.plain-text'], + uniformTypeIdentifiers: const ['public.plain-images']), + throwsA(predicate((Object? e) => + e is AssertionError && + e.message == + 'Only one of uniformTypeIdentifiers or macUTIs can be non-null'))); + }); + + 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', () {