@@ -10,7 +10,8 @@ import 'package:flutter/services.dart';
1010const MethodChannel _channel =
1111 MethodChannel ('plugins.flutter.io/path_provider' );
1212
13- /// Path to the temporary directory on the device.
13+ /// Path to the temporary directory on the device that is not backed up and is
14+ /// suitable for storing caches of downloaded files.
1415///
1516/// Files in this directory may be cleared at any time. This does *not* return
1617/// a new temporary directory. Instead, the caller is responsible for creating
@@ -21,29 +22,47 @@ const MethodChannel _channel =
2122///
2223/// On Android, this uses the `getCacheDir` API on the context.
2324Future <Directory > getTemporaryDirectory () async {
24- // TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
25- // https://github.com/flutter/flutter/issues/26431
26- // ignore: strong_mode_implicit_dynamic_method
27- final String path = await _channel.invokeMethod ('getTemporaryDirectory' );
25+ final String path =
26+ await _channel.invokeMethod <String >('getTemporaryDirectory' );
27+ if (path == null ) {
28+ return null ;
29+ }
30+ return Directory (path);
31+ }
32+
33+ /// Path to a directory where the application may place application support
34+ /// files.
35+ ///
36+ /// Use this for files you don’t want exposed to the user. Your app should not
37+ /// use this directory for user data files.
38+ ///
39+ /// On iOS, this uses the `NSApplicationSupportDirectory` API.
40+ /// If this directory does not exist, it is created automatically.
41+ ///
42+ /// On Android, this function throws an [UnsupportedError] .
43+ Future <Directory > getApplicationSupportDirectory () async {
44+ if (! Platform .isIOS)
45+ throw UnsupportedError ("getApplicationSupportDirectory requires iOS" );
46+ final String path =
47+ await _channel.invokeMethod <String >('getApplicationSupportDirectory' );
2848 if (path == null ) {
2949 return null ;
3050 }
3151 return Directory (path);
3252}
3353
34- /// Path to a directory where the application may place files that are private
35- /// to the application and will only be cleared when the application itself
36- /// is deleted.
54+ /// Path to a directory where the application may place data that is
55+ /// user-generated, or that cannot otherwise be recreated by your application.
3756///
38- /// On iOS, this uses the `NSDocumentsDirectory` API.
57+ /// On iOS, this uses the `NSDocumentDirectory` API. Consider using
58+ /// [getApplicationSupportDirectory] instead if the data is not user-generated.
3959///
40- /// On Android, this returns the AppData directory.
60+ /// On Android, this uses the `getDataDirectory` API on the context. Consider
61+ /// using getExternalStorageDirectory instead if data is intended to be visible
62+ /// to the user.
4163Future <Directory > getApplicationDocumentsDirectory () async {
4264 final String path =
43- // TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
44- // https://github.com/flutter/flutter/issues/26431
45- // ignore: strong_mode_implicit_dynamic_method
46- await _channel.invokeMethod ('getApplicationDocumentsDirectory' );
65+ await _channel.invokeMethod <String >('getApplicationDocumentsDirectory' );
4766 if (path == null ) {
4867 return null ;
4968 }
@@ -54,17 +73,15 @@ Future<Directory> getApplicationDocumentsDirectory() async {
5473/// The current operating system should be determined before issuing this
5574/// function call, as this functionality is only available on Android.
5675///
57- /// On iOS, this function throws an UnsupportedError as it is not possible
76+ /// On iOS, this function throws an [ UnsupportedError] as it is not possible
5877/// to access outside the app's sandbox.
5978///
60- /// On Android this returns getExternalStorageDirectory.
79+ /// On Android this uses the ` getExternalStorageDirectory` API .
6180Future <Directory > getExternalStorageDirectory () async {
6281 if (Platform .isIOS)
6382 throw UnsupportedError ("Functionality not available on iOS" );
64- // TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
65- // https://github.com/flutter/flutter/issues/26431
66- // ignore: strong_mode_implicit_dynamic_method
67- final String path = await _channel.invokeMethod ('getStorageDirectory' );
83+ final String path =
84+ await _channel.invokeMethod <String >('getStorageDirectory' );
6885 if (path == null ) {
6986 return null ;
7087 }
0 commit comments