@@ -51,8 +51,8 @@ PathProviderPlatform get _platform {
5151/// On iOS, this uses the `NSCachesDirectory` API.
5252///
5353/// 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 ();
5656 if (path == null ) {
5757 return null ;
5858 }
@@ -69,8 +69,8 @@ Future<Directory> getTemporaryDirectory() async {
6969/// If this directory does not exist, it is created automatically.
7070///
7171/// 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 ();
7474 if (path == null ) {
7575 return null ;
7676 }
@@ -83,8 +83,8 @@ Future<Directory> getApplicationSupportDirectory() async {
8383///
8484/// On Android, this function throws an [UnsupportedError] as no equivalent
8585/// 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 ();
8888 if (path == null ) {
8989 return null ;
9090 }
@@ -100,8 +100,8 @@ Future<Directory> getLibraryDirectory() async {
100100/// On Android, this uses the `getDataDirectory` API on the context. Consider
101101/// using [getExternalStorageDirectory] instead if data is intended to be visible
102102/// 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 ();
105105 if (path == null ) {
106106 return null ;
107107 }
@@ -116,8 +116,8 @@ Future<Directory> getApplicationDocumentsDirectory() async {
116116/// to access outside the app's sandbox.
117117///
118118/// 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 ();
121121 if (path == null ) {
122122 return null ;
123123 }
@@ -137,8 +137,11 @@ Future<Directory> getExternalStorageDirectory() async {
137137///
138138/// On Android this returns Context.getExternalCacheDirs() or
139139/// 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+ }
142145
143146 return paths.map ((String path) => Directory (path)).toList ();
144147}
@@ -155,13 +158,16 @@ Future<List<Directory>> getExternalCacheDirectories() async {
155158///
156159/// On Android this returns Context.getExternalFilesDirs(String type) or
157160/// Context.getExternalFilesDir(String type) on API levels below 19.
158- Future <List <Directory >> getExternalStorageDirectories ({
161+ Future <List <Directory >? > getExternalStorageDirectories ({
159162 /// Optional parameter. See [StorageDirectory] for more informations on
160163 /// how this type translates to Android storage directories.
161- StorageDirectory type,
164+ StorageDirectory ? type,
162165}) async {
163- final List <String > paths =
166+ final List <String >? paths =
164167 await _platform.getExternalStoragePaths (type: type);
168+ if (paths == null ) {
169+ return null ;
170+ }
165171
166172 return paths.map ((String path) => Directory (path)).toList ();
167173}
@@ -171,8 +177,8 @@ Future<List<Directory>> getExternalStorageDirectories({
171177///
172178/// On Android and on iOS, this function throws an [UnsupportedError] as no equivalent
173179/// 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 ();
176182 if (path == null ) {
177183 return null ;
178184 }
0 commit comments