diff --git a/packages/file_selector/file_selector_platform_interface/CHANGELOG.md b/packages/file_selector/file_selector_platform_interface/CHANGELOG.md index ed720ca0515d..8fcc3e06ef49 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.0.1 + +* Replace extensions with leading dots. + ## 2.0.0 * Migration to null-safety 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 f3f05e2ab3a6..7b3cb12be9f1 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 @@ -10,11 +10,11 @@ class XTypeGroup { /// allowed. XTypeGroup({ this.label, - this.extensions, + List? extensions, this.mimeTypes, this.macUTIs, this.webWildCards, - }); + }) : this.extensions = _removeLeadingDots(extensions); /// The 'name' or reference to this group of types final String? label; @@ -41,4 +41,7 @@ class XTypeGroup { 'webWildCards': webWildCards, }; } + + static List? _removeLeadingDots(List? exts) => + exts?.map((ext) => ext.startsWith('.') ? ext.substring(1) : ext).toList(); } diff --git a/packages/file_selector/file_selector_platform_interface/pubspec.yaml b/packages/file_selector/file_selector_platform_interface/pubspec.yaml index 30398a2f0d23..980730eb2676 100644 --- a/packages/file_selector/file_selector_platform_interface/pubspec.yaml +++ b/packages/file_selector/file_selector_platform_interface/pubspec.yaml @@ -3,7 +3,7 @@ description: A common platform interface for the file_selector plugin. homepage: https://github.com/flutter/plugins/tree/master/packages/file_selector/file_selector_platform_interface # 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.0.0 +version: 2.0.1 dependencies: flutter: 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 99f9fe0f0e3b..c863ad361112 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 @@ -29,14 +29,14 @@ void main() { test('passes the accepted type groups correctly', () async { final group = XTypeGroup( label: 'text', - extensions: ['.txt'], + extensions: ['txt'], mimeTypes: ['text/plain'], macUTIs: ['public.text'], ); final groupTwo = XTypeGroup( label: 'image', - extensions: ['.jpg'], + extensions: ['jpg'], mimeTypes: ['image/jpg'], macUTIs: ['public.image'], webWildCards: ['image/*']); @@ -90,14 +90,14 @@ void main() { test('passes the accepted type groups correctly', () async { final group = XTypeGroup( label: 'text', - extensions: ['.txt'], + extensions: ['txt'], mimeTypes: ['text/plain'], macUTIs: ['public.text'], ); final groupTwo = XTypeGroup( label: 'image', - extensions: ['.jpg'], + extensions: ['jpg'], mimeTypes: ['image/jpg'], macUTIs: ['public.image'], webWildCards: ['image/*']); @@ -152,14 +152,14 @@ void main() { test('passes the accepted type groups correctly', () async { final group = XTypeGroup( label: 'text', - extensions: ['.txt'], + extensions: ['txt'], mimeTypes: ['text/plain'], macUTIs: ['public.text'], ); final groupTwo = XTypeGroup( label: 'image', - extensions: ['.jpg'], + extensions: ['jpg'], mimeTypes: ['image/jpg'], macUTIs: ['public.image'], webWildCards: ['image/*']); 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 bde89f46405d..21bbac5d0f90 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 @@ -9,7 +9,7 @@ void main() { group('XTypeGroup', () { test('toJSON() creates correct map', () { final label = 'test group'; - final extensions = ['.txt', '.jpg']; + final extensions = ['txt', 'jpg']; final mimeTypes = ['text/plain']; final macUTIs = ['public.plain-text']; final webWildCards = ['image/*']; @@ -41,5 +41,12 @@ void main() { expect(jsonMap['macUTIs'], null); expect(jsonMap['webWildCards'], null); }); + + test('Leading dots are removed from extensions', () { + final extensions = ['.txt', '.jpg']; + final group = XTypeGroup(extensions: extensions); + + expect(group.extensions, ['txt', 'jpg']); + }); }); }