resolve method
The absolute path of this folder on the current device.
Throws DiskException when the platform has no such folder.
Implementation
Future<String> resolve() async {
// path_provider calls the OS through FFI, which a background isolate
// can only reach after registering the Dart plugin implementations.
if (!kIsWeb && RootIsolateToken.instance == null) {
DartPluginRegistrant.ensureInitialized();
}
try {
switch (this) {
case DiskRoot.support:
return (await getApplicationSupportDirectory()).path;
case DiskRoot.documents:
return (await getApplicationDocumentsDirectory()).path;
case DiskRoot.cache:
return (await getApplicationCacheDirectory()).path;
case DiskRoot.temporary:
if (Platform.isIOS || Platform.isMacOS) {
return Directory.systemTemp.path;
}
return p.join((await getApplicationCacheDirectory()).path, 'tmp');
case DiskRoot.library:
return (await getLibraryDirectory()).path;
case DiskRoot.downloads:
final Directory? downloads = await getDownloadsDirectory();
if (downloads == null) throw UnsupportedError('No downloads folder');
return downloads.path;
case DiskRoot.external:
final Directory? external = await getExternalStorageDirectory();
if (external == null) throw UnsupportedError('No external storage');
return external.path;
}
} catch (error) {
throw DiskException(
'Could not find the $name folder on this platform',
cause: error,
);
}
}