getExternalStorageDirectory function Null safety

Future<Directory?> getExternalStorageDirectory()

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 getExternalFilesDir(null).


Future<Directory?> getExternalStorageDirectory() async {
  final String? path = await _platform.getExternalStoragePath();
  if (path == null) {
    return null;
  return Directory(path);