This repository was archived by the owner on Feb 22, 2023. It is now read-only.
File tree 2 files changed +6
-21
lines changed
packages/file_selector/file_selector_platform_interface
lib/src/types/x_type_group
2 files changed +6
-21
lines changed Original file line number Diff line number Diff line change 1
1
// Copyright 2020 The Flutter Authors. All rights reserved.
2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
- import 'package:flutter/foundation.dart' ;
5
4
6
5
/// A set of allowed XTypes
7
6
class XTypeGroup {
@@ -11,27 +10,11 @@ class XTypeGroup {
11
10
/// allowed.
12
11
XTypeGroup ({
13
12
this .label,
14
- this . extensions,
13
+ List < String > ? extensions,
15
14
this .mimeTypes,
16
15
this .macUTIs,
17
16
this .webWildCards,
18
- }) {
19
- _verifyExtensions ();
20
- }
21
-
22
- void _verifyExtensions () {
23
- if (extensions == null ) return ;
24
- final exts = extensions! ;
25
- for (var i = 0 ; i < exts.length; i++ ) {
26
- if (! exts[i].startsWith ('.' )) continue ;
27
- if (kDebugMode) {
28
- print ('extensions[${i }] with value "${exts [i ]}" is invalid.'
29
- ' The leading dots are being removed from the extensions'
30
- ' Please fix it.' );
31
- }
32
- exts[i] = exts[i].substring (1 );
33
- }
34
- }
17
+ }) : this .extensions = _removeLeadingDots (extensions);
35
18
36
19
/// The 'name' or reference to this group of types
37
20
final String ? label;
@@ -58,4 +41,7 @@ class XTypeGroup {
58
41
'webWildCards' : webWildCards,
59
42
};
60
43
}
44
+
45
+ static List <String >? _removeLeadingDots (List <String >? exts) =>
46
+ exts? .map ((ext) => ext.startsWith ('.' ) ? ext.substring (1 ) : ext).toList ();
61
47
}
Original file line number Diff line number Diff line change @@ -42,11 +42,10 @@ void main() {
42
42
expect (jsonMap['webWildCards' ], null );
43
43
});
44
44
45
- test ('Validates extensions have not leading dots ' , () {
45
+ test ('Leading dots are removed from extensions ' , () {
46
46
final extensions = ['.txt' , '.jpg' ];
47
47
final group = XTypeGroup (extensions: extensions);
48
48
49
- expect (group.extensions, extensions);
50
49
expect (group.extensions, ['txt' , 'jpg' ]);
51
50
});
52
51
});
You can’t perform that action at this time.
0 commit comments