Skip to content

Commit 2f469e1

Browse files
committed
fixed scenario of throwing stateError
1 parent 5fd169b commit 2f469e1

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

packages/path_provider/path_provider_android/lib/path_provider_android.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ class PathProviderAndroid extends PathProviderPlatform {
8484
Future<String?> getDownloadsPath() async {
8585
final List<String>? paths =
8686
await getExternalStoragePaths(type: StorageDirectory.downloads);
87-
return paths?.first;
87+
if (paths != null && paths.isNotEmpty) {
88+
return paths.first;
89+
}
90+
return null;
8891
}
8992
}

packages/path_provider/path_provider_android/test/path_provider_android_test.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,11 @@ void main() {
9393
final String? path = await pathProvider.getDownloadsPath();
9494
expect(path, kExternalStoragePaths);
9595
});
96+
97+
//TODO: override externalStoragePaths as empty
98+
test('getDownloadsPath null', () async {
99+
final String? path = await pathProvider.getDownloadsPath();
100+
expect(path, null);
101+
});
96102
});
97103
}

0 commit comments

Comments
 (0)