-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathpath_provider.dart
90 lines (85 loc) · 2.63 KB
/
path_provider.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
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
class MyPathProvider extends StatefulWidget {
const MyPathProvider({Key? key}) : super(key: key);
@override
State<MyPathProvider> createState() => _MyPathProviderState();
}
class _MyPathProviderState extends State<MyPathProvider> {
TextStyle textStyle = const TextStyle(fontSize: 20);
String? tempPath;
String? permanentPath;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Path Provider'),
actions: [
IconButton(
onPressed: () {
setState(() {
tempPath = null;
permanentPath = null;
});
},
icon: const Icon(Icons.refresh),
),
],
),
body: Column(
children: [
Expanded(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Temp Path: $tempPath',
textAlign: TextAlign.center,
),
const SizedBox(height: 30),
TextButton.icon(
icon: const Icon(Icons.account_tree_outlined),
label: Text('Temp Path', style: textStyle),
onPressed: () async {
Directory tempDir = await getTemporaryDirectory();
setState(() {
tempPath = tempDir.path;
});
},
),
],
),
),
),
Expanded(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Permanent Path: $permanentPath',
textAlign: TextAlign.center,
),
const SizedBox(height: 30),
TextButton.icon(
icon: const Icon(Icons.account_tree_sharp),
label: Text('Permanent Path', style: textStyle),
onPressed: () async {
Directory permDir =
await getApplicationDocumentsDirectory();
setState(() {
permanentPath = permDir.path;
});
},
),
],
),
),
),
],
),
);
}
}