Line data Source code
1 : // Copyright 2023 The terCAD team. All rights reserved.
2 : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.
3 :
4 : import 'package:file_picker/file_picker.dart';
5 : import 'package:flutter/foundation.dart';
6 :
7 : mixin FileImportMixin {
8 0 : Future<Uint8List?> importFileBytes(List<String> ext) async {
9 : final PlatformFile? file;
10 0 : if (defaultTargetPlatform == TargetPlatform.android) {
11 0 : file = await FilePicker.pickFile(type: FileType.any);
12 : } else {
13 0 : file = await FilePicker.pickFile(type: FileType.custom, allowedExtensions: ext);
14 : }
15 0 : return file != null ? await file.readAsBytes() : null;
16 : }
17 :
18 0 : Future<String?> importFile(List<String> ext) async {
19 0 : final bytes = await importFileBytes(ext);
20 0 : return bytes != null ? String.fromCharCodes(bytes) : null;
21 : }
22 : }
|