@@ -51,8 +51,8 @@ PathProviderPlatform get _platform {
51
51
/// On iOS, this uses the `NSCachesDirectory` API.
52
52
///
53
53
/// On Android, this uses the `getCacheDir` API on the context.
54
- Future <Directory > getTemporaryDirectory () async {
55
- final String path = await _platform.getTemporaryPath ();
54
+ Future <Directory ? > getTemporaryDirectory () async {
55
+ final String ? path = await _platform.getTemporaryPath ();
56
56
if (path == null ) {
57
57
return null ;
58
58
}
@@ -69,8 +69,8 @@ Future<Directory> getTemporaryDirectory() async {
69
69
/// If this directory does not exist, it is created automatically.
70
70
///
71
71
/// On Android, this function uses the `getFilesDir` API on the context.
72
- Future <Directory > getApplicationSupportDirectory () async {
73
- final String path = await _platform.getApplicationSupportPath ();
72
+ Future <Directory ? > getApplicationSupportDirectory () async {
73
+ final String ? path = await _platform.getApplicationSupportPath ();
74
74
if (path == null ) {
75
75
return null ;
76
76
}
@@ -83,8 +83,8 @@ Future<Directory> getApplicationSupportDirectory() async {
83
83
///
84
84
/// On Android, this function throws an [UnsupportedError] as no equivalent
85
85
/// path exists.
86
- Future <Directory > getLibraryDirectory () async {
87
- final String path = await _platform.getLibraryPath ();
86
+ Future <Directory ? > getLibraryDirectory () async {
87
+ final String ? path = await _platform.getLibraryPath ();
88
88
if (path == null ) {
89
89
return null ;
90
90
}
@@ -100,8 +100,8 @@ Future<Directory> getLibraryDirectory() async {
100
100
/// On Android, this uses the `getDataDirectory` API on the context. Consider
101
101
/// using [getExternalStorageDirectory] instead if data is intended to be visible
102
102
/// to the user.
103
- Future <Directory > getApplicationDocumentsDirectory () async {
104
- final String path = await _platform.getApplicationDocumentsPath ();
103
+ Future <Directory ? > getApplicationDocumentsDirectory () async {
104
+ final String ? path = await _platform.getApplicationDocumentsPath ();
105
105
if (path == null ) {
106
106
return null ;
107
107
}
@@ -116,8 +116,8 @@ Future<Directory> getApplicationDocumentsDirectory() async {
116
116
/// to access outside the app's sandbox.
117
117
///
118
118
/// On Android this uses the `getExternalFilesDir(null)` .
119
- Future <Directory > getExternalStorageDirectory () async {
120
- final String path = await _platform.getExternalStoragePath ();
119
+ Future <Directory ? > getExternalStorageDirectory () async {
120
+ final String ? path = await _platform.getExternalStoragePath ();
121
121
if (path == null ) {
122
122
return null ;
123
123
}
@@ -137,8 +137,11 @@ Future<Directory> getExternalStorageDirectory() async {
137
137
///
138
138
/// On Android this returns Context.getExternalCacheDirs() or
139
139
/// Context.getExternalCacheDir() on API levels below 19.
140
- Future <List <Directory >> getExternalCacheDirectories () async {
141
- final List <String > paths = await _platform.getExternalCachePaths ();
140
+ Future <List <Directory >?> getExternalCacheDirectories () async {
141
+ final List <String >? paths = await _platform.getExternalCachePaths ();
142
+ if (paths == null ) {
143
+ return null ;
144
+ }
142
145
143
146
return paths.map ((String path) => Directory (path)).toList ();
144
147
}
@@ -155,13 +158,16 @@ Future<List<Directory>> getExternalCacheDirectories() async {
155
158
///
156
159
/// On Android this returns Context.getExternalFilesDirs(String type) or
157
160
/// Context.getExternalFilesDir(String type) on API levels below 19.
158
- Future <List <Directory >> getExternalStorageDirectories ({
161
+ Future <List <Directory >? > getExternalStorageDirectories ({
159
162
/// Optional parameter. See [StorageDirectory] for more informations on
160
163
/// how this type translates to Android storage directories.
161
- StorageDirectory type,
164
+ StorageDirectory ? type,
162
165
}) async {
163
- final List <String > paths =
166
+ final List <String >? paths =
164
167
await _platform.getExternalStoragePaths (type: type);
168
+ if (paths == null ) {
169
+ return null ;
170
+ }
165
171
166
172
return paths.map ((String path) => Directory (path)).toList ();
167
173
}
@@ -171,8 +177,8 @@ Future<List<Directory>> getExternalStorageDirectories({
171
177
///
172
178
/// On Android and on iOS, this function throws an [UnsupportedError] as no equivalent
173
179
/// path exists.
174
- Future <Directory > getDownloadsDirectory () async {
175
- final String path = await _platform.getDownloadsPath ();
180
+ Future <Directory ? > getDownloadsDirectory () async {
181
+ final String ? path = await _platform.getDownloadsPath ();
176
182
if (path == null ) {
177
183
return null ;
178
184
}
0 commit comments