This repository was archived by the owner on Feb 22, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +6
-21
lines changed
packages/file_selector/file_selector_platform_interface
lib/src/types/x_type_group Expand file tree Collapse file tree 2 files changed +6
-21
lines changed Original file line number Diff line number Diff line change 11// Copyright 2020 The Flutter Authors. All rights reserved.
22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
4- import 'package:flutter/foundation.dart' ;
54
65/// A set of allowed XTypes
76class XTypeGroup {
@@ -11,27 +10,11 @@ class XTypeGroup {
1110 /// allowed.
1211 XTypeGroup ({
1312 this .label,
14- this . extensions,
13+ List < String > ? extensions,
1514 this .mimeTypes,
1615 this .macUTIs,
1716 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);
3518
3619 /// The 'name' or reference to this group of types
3720 final String ? label;
@@ -58,4 +41,7 @@ class XTypeGroup {
5841 'webWildCards' : webWildCards,
5942 };
6043 }
44+
45+ static List <String >? _removeLeadingDots (List <String >? exts) =>
46+ exts? .map ((ext) => ext.startsWith ('.' ) ? ext.substring (1 ) : ext).toList ();
6147}
Original file line number Diff line number Diff line change @@ -42,11 +42,10 @@ void main() {
4242 expect (jsonMap['webWildCards' ], null );
4343 });
4444
45- test ('Validates extensions have not leading dots ' , () {
45+ test ('Leading dots are removed from extensions ' , () {
4646 final extensions = ['.txt' , '.jpg' ];
4747 final group = XTypeGroup (extensions: extensions);
4848
49- expect (group.extensions, extensions);
5049 expect (group.extensions, ['txt' , 'jpg' ]);
5150 });
5251 });
You can’t perform that action at this time.
0 commit comments