A Flutter plugin to retrieve information about device storage.
This plugin provides methods to get information about both internal and external storage space on an Android device.
To use this plugin, add flutter_storage_info as a dependency in your pubspec.yaml file.
dependencies:
flutter_storage_info: ^1.0.0import 'package:flutter_storage_info/flutter_storage_info.dart';import 'package:flutter_storage_info/flutter_storage_info.dart';
void main() async {
// Fetch the storage info
int totalSpace = await FlutterStorageInfo.storageTotalSpace;
int freeSpace = await FlutterStorageInfo.storageFreeSpace;
int usedSpace = await FlutterStorageInfo.storageUsedSpace;
print('Total Space: $totalSpace bytes');
print('Free Space: $freeSpace bytes');
print('Used Space: $usedSpace bytes');
}The following methods are provided by the FlutterStorageInfo class:
storageFreeSpace: Retrieves the amount of free space available on the device's internal storage in bytes.storageTotalSpace: Retrieves the total amount of space available on the device's internal storage in bytes.storageUsedSpace: Retrieves the amount of used space on the device's internal storage in bytes.
externalStorageFreeSpace: Retrieves the amount of free space available on the device's external storage in bytes.externalStorageTotalSpace: Retrieves the total amount of space available on the device's external storage in bytes.externalStorageUsedSpace: Retrieves the amount of used space on the device's external storage in bytes.
getStorageSpaceInMB(String method): Retrieves the specified storage space in megabytes (MB).getStorageSpaceInGB(String method): Retrieves the specified storage space in gigabytes (GB).
getSizeOfDirectoryInMB(String directory): Retrieves the size of the specified directory in megabytes (MB).
getStorageTypeFromPath(String path): Determines whether the specified path corresponds to internal or external storage. Returns aDeviceStorageTypeenum value (internalorexternal).
calculateStorageUsage(double storageUsed, double storageTotal): Calculates the storage usage value as a ratio (storageUsed / storageTotal). Throws an exception ifstorageTotalis less than or equal to zero.
isLowOnStorage(DeviceStorageType storageType, {double threshold = 0.98}): Checks if the storage usage exceeds the specified threshold (default is 98%). Returnstrueif usage is above the threshold, otherwisefalse.
String directoryPath = '/storage/emulated/0/Movies/MyFolder';
double directorySize = await FlutterStorageInfo.getSizeOfDirectoryInMB(directoryPath);
print('Directory Size: $directorySize MB');String path = '/storage/emulated/0/Android';
DeviceStorageType storageType = FlutterStorageInfo.getStorageTypeFromPath(path);
print('Storage Type: $storageType');double storageTotal = await FlutterStorageInfo.getStorageSpaceInGB('getStorageTotalSpaceInGB');
double storageUsed = await FlutterStorageInfo.getStorageSpaceInGB('getStorageUsedSpaceInGB');
double usageValue = FlutterStorageInfo.calculateStorageUsage(storageUsed, storageTotal);
print('Storage Usage Value: $usageValue');DeviceStorageType storageType = DeviceStorageType.internal;
double threshold = 0.95;
bool isLow = await FlutterStorageInfo.isLowOnStorage(storageType, threshold: threshold);
print('Is Low on Storage: $isLow');Add the following permissions to your AndroidManifest.xml file:
<manifest xmlns:android="https://schemas.android.com/apk/res/android"
package="com.jaberio.app">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
</manifest>- Android (β )
- iOS (π)
- Linux (β)
- macOS (β)
- Windows (β)
Please file issues to send feedback or report a bug. Thank you!
