flutter_storage_info 1.0.0
flutter_storage_info: ^1.0.0 copied to clipboard
Flutter plugin for retrieving storage information. Easily get details on device storage usage. Reliable and efficient.
Flutter Storage Info #
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.
Usage #
To use this plugin, add flutter_storage_info as a dependency in your pubspec.yaml file.
dependencies:
flutter_storage_info: ^1.0.0
import 'package:flutter_storage_info/flutter_storage_info.dart';
Example #
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');
}
Methods #
The following methods are provided by the FlutterStorageInfo class:
Internal Storage (Device Storage) #
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.
External Storage (SD Card) #
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.
Conversion Methods #
getStorageSpaceInMB(String method): Retrieves the specified storage space in megabytes (MB).getStorageSpaceInGB(String method): Retrieves the specified storage space in gigabytes (GB).
Directory Size #
getSizeOfDirectoryInMB(String directory): Retrieves the size of the specified directory in megabytes (MB).
Storage Type Detection #
getStorageTypeFromPath(String path): Determines whether the specified path corresponds to internal or external storage. Returns aDeviceStorageTypeenum value (internalorexternal).
Storage Usage Calculation #
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.
Low Storage Detection #
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.
Examples #
Get the size of a directory in MB #
String directoryPath = '/storage/emulated/0/Movies/MyFolder';
double directorySize = await FlutterStorageInfo.getSizeOfDirectoryInMB(directoryPath);
print('Directory Size: $directorySize MB');
Determine the storage type from a path #
String path = '/storage/emulated/0/Android';
DeviceStorageType storageType = FlutterStorageInfo.getStorageTypeFromPath(path);
print('Storage Type: $storageType');
Calculate storage usage value #
double storageTotal = await FlutterStorageInfo.getStorageSpaceInGB('getStorageTotalSpaceInGB');
double storageUsed = await FlutterStorageInfo.getStorageSpaceInGB('getStorageUsedSpaceInGB');
double usageValue = FlutterStorageInfo.calculateStorageUsage(storageUsed, storageTotal);
print('Storage Usage Value: $usageValue');
Check if storage is low #
DeviceStorageType storageType = DeviceStorageType.internal;
double threshold = 0.95;
bool isLow = await FlutterStorageInfo.isLowOnStorage(storageType, threshold: threshold);
print('Is Low on Storage: $isLow');
Screenshot #

Permissions #
Android #
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>
Supported Platforms #
- Android (✅)
- iOS (🕑)
- Linux (❌)
- macOS (❌)
- Windows (❌)
Automated Publishing #
This repository is configured to automatically publish to pub.dev when a new release tag is pushed.
How to use: #
- Bump the version in
pubspec.yamland updateCHANGELOG.md. - Commit and push the changes to
main. - Create and push a new tag:
The GitHub Action will automatically run analysis, tests, and publish the package if all checks pass.git tag v1.0.0 git push origin v1.0.0
Important
To enable this, you must enable automated publishing on pub.dev for this package and link it to this GitHub repository.
Issues and Feedback #
Please file issues to send feedback or report a bug. Thank you!