-
Notifications
You must be signed in to change notification settings - Fork 621
Expand file tree
/
Copy pathmain.dart
More file actions
122 lines (109 loc) · 3.51 KB
/
Copy pathmain.dart
File metadata and controls
122 lines (109 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:open_file_android/open_file_android.dart';
import 'package:permission_handler/permission_handler.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
var _openResult = 'Unknown';
Future<void> openFile() async {
_openPickFile();
}
// ignore: unused_element
_openPickFile() async {
FilePickerResult? fileResult = await FilePicker.platform.pickFiles();
if (fileResult?.files.first != null) {
final result = await OpenFileAndroid().open(fileResult!.files.first.path);
setState(() {
_openResult = "type=${result.type} message=${result.message}";
});
}
}
// ignore: unused_element
_openAppPrivateFile() async {
//open an app private storage file
final result = await OpenFileAndroid().open(
"/data/data/com.crazecoder.openfileexample/cache/IMG20230610192318.jpg");
setState(() {
_openResult = "type=${result.type} message=${result.message}";
});
}
// ignore: unused_element
_openOtherAppFile() async {
//open an external storage image file on android 13
if (await Permission.manageExternalStorage.request().isGranted) {
final result =
await OpenFileAndroid().open("/data/user/0/xxx/images/1.jpg");
setState(() {
_openResult = "type=${result.type} message=${result.message}";
});
}
}
// ignore: unused_element
_openExternalImage() async {
//open an external storage image file on android 13
// if (await Permission.photos.request().isGranted) {
final result = await OpenFileAndroid().open("/sdcard/Download/R-C.jpg");
setState(() {
_openResult = "type=${result.type} message=${result.message}";
});
// }
}
// ignore: unused_element
_openExternalVideo() async {
//open an external storage video file on android 13
if (await Permission.videos.request().isGranted) {
final result = await OpenFileAndroid().open("/sdcard/Download/R-C.mp4");
setState(() {
_openResult = "type=${result.type} message=${result.message}";
});
}
}
// ignore: unused_element
_openExternalAudio() async {
//open an external storage audio file on android 13
if (await Permission.audio.request().isGranted) {
final result = await OpenFileAndroid().open("/sdcard/Download/R-C.mp3");
setState(() {
_openResult = "type=${result.type} message=${result.message}";
});
}
}
// ignore: unused_element
_openExternalFile() async {
//open an external storage file
if (await Permission.manageExternalStorage.request().isGranted) {
final result =
await OpenFileAndroid().open("/sdcard/Android/data/R-C.xml");
setState(() {
_openResult = "type=${result.type} message=${result.message}";
});
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('open result: $_openResult\n'),
TextButton(
child: Text('Tap to open file'),
onPressed: openFile,
),
],
),
),
),
);
}
}