-
Notifications
You must be signed in to change notification settings - Fork 15
/
main.dart
143 lines (135 loc) · 3.98 KB
/
main.dart
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import 'dart:io';
import 'package:permission_handler/permission_handler.dart';
import 'package:flutter/material.dart';
import 'package:saf/saf.dart';
/// Edit the Directory Programmatically Here
const directory = "Android/media/matrix/.neo";
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late Saf saf;
var _paths = [];
@override
void initState() {
Permission.storage.request();
saf = Saf(directory);
super.initState();
}
loadImage(paths, {String k = ""}) {
var tempPaths = [];
for (String path in paths) {
if (path.endsWith(".jpg")) {
tempPaths.add(path);
}
}
if (k.isNotEmpty) tempPaths.add(k);
_paths = tempPaths;
setState(() {});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Saf example app'),
),
body: Center(
child: SingleChildScrollView(
child: Column(
children: [
if (_paths.isNotEmpty)
..._paths.map(
(path) => Card(
child: Image.file(
File(path),
),
),
)
],
),
),
),
bottomNavigationBar: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(Colors.deepPurpleAccent),
),
onPressed: () async {
Saf.releasePersistedPermissions();
},
child: const Text("Release*"),
),
ElevatedButton(
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(Colors.blueGrey.shade700),
),
onPressed: () async {
var cachedFilesPath = await saf.cache();
if (cachedFilesPath != null) {
loadImage(cachedFilesPath);
}
},
child: const Text("Cache"),
),
ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.green),
),
onPressed: () async {
var isSync = await saf.sync();
if (isSync as bool) {
var _paths = await saf.getCachedFilesPath();
loadImage(_paths);
}
},
child: const Text("Sync"),
),
ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.orange),
),
onPressed: () async {
var isClear = await saf.clearCache();
if (isClear != null && isClear) {
loadImage([]);
}
},
child: const Text("Clear"),
),
],
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: FloatingActionButton(
elevation: 30.0,
backgroundColor: Colors.black,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Text(
"GRANT",
style: TextStyle(fontSize: 13, color: Colors.red),
),
Text(
"Permission",
style: TextStyle(fontSize: 7.8, color: Colors.red),
)
],
),
onPressed: () async {
await saf.getDirectoryPermission(isDynamic: true);
},
),
),
);
}
}