forked from flutter-team-archive/plugins
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpath_provider.dart
More file actions
91 lines (84 loc) · 3.3 KB
/
Copy pathpath_provider.dart
File metadata and controls
91 lines (84 loc) · 3.3 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
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:io';
import 'package:flutter/services.dart';
const MethodChannel _channel =
MethodChannel('plugins.flutter.io/path_provider');
/// Path to the temporary directory on the device that is not backed up and is
/// suitable for storing caches of downloaded files.
///
/// Files in this directory may be cleared at any time. This does *not* return
/// a new temporary directory. Instead, the caller is responsible for creating
/// (and cleaning up) files or directories within this directory. This
/// directory is scoped to the calling application.
///
/// On iOS, this uses the `NSCachesDirectory` API.
///
/// On Android, this uses the `getCacheDir` API on the context.
Future<Directory> getTemporaryDirectory() async {
final String path =
await _channel.invokeMethod<String>('getTemporaryDirectory');
if (path == null) {
return null;
}
return Directory(path);
}
/// Path to a directory where the application may place application support
/// files.
///
/// Use this for files you don’t want exposed to the user. Your app should not
/// use this directory for user data files.
///
/// On iOS, this uses the `NSApplicationSupportDirectory` API.
/// If this directory does not exist, it is created automatically.
///
/// On Android, this function throws an [UnsupportedError].
Future<Directory> getApplicationSupportDirectory() async {
if (!(Platform.isIOS || Platform.isMacOS))
throw UnsupportedError("getApplicationSupportDirectory requires iOS or macOS");
final String path =
await _channel.invokeMethod<String>('getApplicationSupportDirectory');
if (path == null) {
return null;
}
return Directory(path);
}
/// Path to a directory where the application may place data that is
/// user-generated, or that cannot otherwise be recreated by your application.
///
/// On iOS, this uses the `NSDocumentDirectory` API. Consider using
/// [getApplicationSupportDirectory] instead if the data is not user-generated.
///
/// On Android, this uses the `getDataDirectory` API on the context. Consider
/// using getExternalStorageDirectory instead if data is intended to be visible
/// to the user.
Future<Directory> getApplicationDocumentsDirectory() async {
final String path =
await _channel.invokeMethod<String>('getApplicationDocumentsDirectory');
if (path == null) {
return null;
}
return Directory(path);
}
/// Path to a directory where the application may access top level storage.
/// The current operating system should be determined before issuing this
/// function call, as this functionality is only available on Android.
///
/// On iOS, this function throws an [UnsupportedError] as it is not possible
/// to access outside the app's sandbox.
///
/// On Android this uses the `getExternalStorageDirectory` API.
Future<Directory> getExternalStorageDirectory() async {
if (Platform.isIOS)
throw UnsupportedError("Functionality not available on iOS");
if (Platform.isMacOS)
throw UnsupportedError("Functionality not implemented on macOS");
final String path =
await _channel.invokeMethod<String>('getStorageDirectory');
if (path == null) {
return null;
}
return Directory(path);
}