@@ -14,7 +14,7 @@ Future<XFile> openFile({
14
14
String initialDirectory,
15
15
String confirmButtonText,
16
16
}) {
17
- _verifyExtensions (acceptedTypeGroups);
17
+ acceptedTypeGroups = _verifyTypeGroups (acceptedTypeGroups);
18
18
return FileSelectorPlatform .instance.openFile (
19
19
acceptedTypeGroups: acceptedTypeGroups,
20
20
initialDirectory: initialDirectory,
@@ -27,7 +27,7 @@ Future<List<XFile>> openFiles({
27
27
String initialDirectory,
28
28
String confirmButtonText,
29
29
}) {
30
- _verifyExtensions (acceptedTypeGroups);
30
+ acceptedTypeGroups = _verifyTypeGroups (acceptedTypeGroups);
31
31
return FileSelectorPlatform .instance.openFiles (
32
32
acceptedTypeGroups: acceptedTypeGroups,
33
33
initialDirectory: initialDirectory,
@@ -41,7 +41,7 @@ Future<String> getSavePath({
41
41
String suggestedName,
42
42
String confirmButtonText,
43
43
}) async {
44
- _verifyExtensions (acceptedTypeGroups);
44
+ acceptedTypeGroups = _verifyTypeGroups (acceptedTypeGroups);
45
45
return FileSelectorPlatform .instance.getSavePath (
46
46
acceptedTypeGroups: acceptedTypeGroups,
47
47
initialDirectory: initialDirectory,
@@ -58,15 +58,21 @@ Future<String> getDirectoryPath({
58
58
initialDirectory: initialDirectory, confirmButtonText: confirmButtonText);
59
59
}
60
60
61
- void _verifyExtensions (List <XTypeGroup > acceptedTypeGroups) {
62
- acceptedTypeGroups? .asMap ()? .forEach ((i, acceptedTypeGroup) {
63
- acceptedTypeGroup.extensions? .asMap ()? .forEach ((j, ext) {
64
- if (kDebugMode && ext.startsWith ('.' )) {
65
- print (
66
- 'acceptedTypeGroups[${i }].extensions[${j }] with value "${ext }" is invalid.'
67
- ' Remove the leading dot.' ,
68
- );
61
+ List <XTypeGroup > _verifyTypeGroups (List <XTypeGroup > groups) {
62
+ if (groups == null ) return groups;
63
+ for (var i = 0 ; i < groups.length; i++ ) {
64
+ if (groups[i] == null || groups[i].extensions == null ) continue ;
65
+ for (var j = 0 ; j < groups[i].extensions.length; j++ ) {
66
+ if (groups[i].extensions[j] == null ) continue ;
67
+ if (groups[i].extensions[j].startsWith ('.' )) {
68
+ if (kDebugMode) {
69
+ print ('acceptedTypeGroups[${i }].extensions[${j }]'
70
+ ' with value "${groups [i ].extensions [j ]} is invalid.'
71
+ ' Please remove the leading dot.' );
72
+ }
73
+ groups[i].extensions[j] = groups[i].extensions[j].substring (1 );
69
74
}
70
- });
71
- });
75
+ }
76
+ }
77
+ return groups;
72
78
}
0 commit comments