11import 'dart:async' ;
2- import 'dart:io' ;
32
3+ import 'package:butterfly/visualizer/asset.dart' ;
44import 'package:butterfly_api/butterfly_api.dart' ;
5- import 'package:file_picker/file_picker .dart' ;
5+ import 'package:file_selector/file_selector .dart' as fs ;
66import 'package:flutter/foundation.dart' ;
77import 'package:flutter/material.dart' ;
88import 'package:go_router/go_router.dart' ;
@@ -18,21 +18,19 @@ Future<bool> openHelp(List<String> pageLocation, [String? fragment]) {
1818 mode: LaunchMode .externalApplication);
1919}
2020
21- Future <(Uint8List ?, String ?)> openSupported (
22- [List <String >? fileExtension]) async {
23- final isMobile = ! kIsWeb && (Platform .isAndroid || Platform .isIOS);
24- final files = await FilePicker .platform.pickFiles (
25- type: isMobile ? FileType .any : FileType .custom,
26- allowedExtensions: isMobile
27- ? null
28- : (fileExtension ??
29- AssetFileType .values.expand ((e) => e.getFileExtensions ()).toList ()),
30- allowMultiple: false ,
31- withData: true ,
21+ Future <(Uint8List ?, String ?)> importFile (BuildContext context,
22+ [List <AssetFileType >? types]) async {
23+ final result = await fs.openFile (
24+ acceptedTypeGroups: (types ?? AssetFileType .values)
25+ .map ((e) => fs.XTypeGroup (
26+ label: e.getLocalizedName (context),
27+ extensions: e.getFileExtensions (),
28+ mimeTypes: [e.getMime ()],
29+ ))
30+ .toList (),
3231 );
33- if (files? .files.isEmpty ?? true ) return (null , null );
34- var e = files! .files.first;
35- return (e.bytes, e.extension );
32+ final data = await result? .readAsBytes ();
33+ return (data, result? .name.split ('.' ).lastOrNull);
3634}
3735
3836Future <void > openFile (
0 commit comments