Environment
WARNING This API is deprecated and will be removed soon. If you need it, please open an issue with your use-case to include in the next release as part of the new original cross-platform API.
Import package¶
import 'package:shared_storage/shared_storage.dart' as shared_storage;
Usage sample:
shared_storage.getRootDirectory(...);
shared_storage.getExternalStoragePublicDirectory(...);
But if you import without alias import '...';
(Not recommeded because can conflict with other method/package names) you should use directly as functions:
getRootDirectory(...);
getExternalStoragePublicDirectory(...);
Mirror methods¶
Mirror methods are available to provide an way to call a native method without using any abstraction, available mirror methods:
getRootDirectory¶
Mirror of Environment.getRootDirectory
Return root of the "system" partition holding the core Android OS. Always present and mounted read-only.
Warning Some new Android versions return null because
SAF
is the new API to handle storage.
final Directory? rootDir = await getRootDirectory();
getExternalStoragePublicDirectory¶
Mirror of Environment.getExternalStoragePublicDirectory
Get a top-level shared/external storage directory for placing files of a particular type. This is where the user will typically place and manage their own files, so you should be careful about what you put here to ensure you don't erase their files or get in the way of their own organization.
Warning Some new Android versions return null because
SAF
is the new API to handle storage.
final Directory? externalPublicDir = await getExternalStoragePublicDirectory(EnvironmentDirectory.downloads);
getExternalStorageDirectory¶
Mirror of Environment.getExternalStorageDirectory
Return the primary shared/external storage directory. This directory may not currently be accessible if it has been mounted by the user on their computer, has been removed from the device, or some other problem has happened.
Warning Some new Android versions return null because
SAF
is the new API to handle storage.
final Directory? externalDir = await getExternalStorageDirectory();
getDataDirectory¶
Mirror of Environment.getDataDirectory
Return the user data directory.
Info What may not be obvious is that the "user data directory" returned by
Environment.getDataDirectory
is the system-wide data directory (i.e, typically so far/data
) and not an application specific directory. Applications of course are not allowed to write to the overall data directory, but only to their particular folder inside it or other select locations whose owner has granted access. Reference by Chris StrattonWarning Some new Android versions return null because
SAF
is the new API to handle storage.
final Directory? dataDir = await getDataDirectory();
getDownloadCacheDirectory¶
Mirror of Environment.getDownloadCacheDirectory
Return the download/cache content directory.
Typically the /data/cache
directory.
Warning Some new Android versions return null because
SAF
is the new API to handle storage.
final Directory? downloadCacheDir = await getDownloadCacheDirectory();
getStorageDirectory¶
Mirror of Environment.getStorageDirectory
Return root directory where all external storage devices will be mounted. For example, getExternalStorageDirectory()
will appear under this location.
Warning Some new Android versions return null because
SAF
is the new API to handle storage.
final Directory? storageDir = await getStorageDirectory();
Android Official Documentation¶
The Environment official documentation is available here.
All the APIs listed in this plugin module are derivated from the official docs.