flutter_storage_info

Last updated:

0 purchases

flutter_storage_info Image
flutter_storage_info Images
Add to Cart

Description:

flutter storage info

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: ^0.0.5
copied to clipboard
import 'package:flutter_storage_info/flutter_storage_info.dart';
copied to clipboard
Example #
import 'package:flutter_storage_info/flutter_storage_info.dart';

void main() async {
// Fetch the storage info
final flutterStorageInfo = FlutterStorageInfo();
double totalSpace = await flutterStorageInfo.getTotalDiskSpace;
double freeSpace = await flutterStorageInfo.getFreeDiskSpace;
double usedSpace = await flutterStorageInfo.getUsedDiskSpace;

print('Total Space: $totalSpace');
print('Free Space: $freeSpace');
print('Used Space: $usedSpace');

}
copied to clipboard
Methods #

You can access all the methods using the flutterStorageInfo object as shown below:

final flutterStorageInfo = FlutterStorageInfo();
copied to clipboard
Internal Storage (Device Storage) #

getFreeDiskSpace: Returns the amount of free space available on the device's internal storage.
getTotalDiskSpace: Returns the total amount of space available on the device's internal storage.
getUsedDiskSpace: Returns the amount of used space on the device's internal storage.
getFreeDiskSpaceInGB: Returns the amount of free space available on the device's internal storage in gigabytes.
getTotalDiskSpaceInGB: Returns the total amount of space available on the device's internal storage in gigabytes.
getUsedDiskSpaceInGB: Returns the amount of used space on the device's internal storage in gigabytes.
getFreeDiskSpaceInMB: Returns the amount of free space available on the device's internal storage in megabytes.
getTotalDiskSpaceInMB: Returns the total amount of space available on the device's internal storage in megabytes.
getUsedDiskSpaceInMB: Returns the amount of used space on the device's internal storage in megabytes.

External Storage (SD Card) #

getFreeExternalDiskSpace: Returns the amount of free space available on the device's external storage.
getTotalExternalDiskSpace: Returns the total amount of space available on the device's external storage.
getUsedExternalDiskSpace: Returns the amount of used space on the device's external storage.
getFreeExternalDiskSpaceInGB: Returns the amount of free space available on the device's external storage in gigabytes.
getTotalExternalDiskSpaceInGB: Returns the total amount of space available on the device's external storage in gigabytes.
getUsedExternalDiskSpaceInGB: Returns the amount of used space on the device's external storage in gigabytes.
getFreeExternalDiskSpaceInMB: Returns the amount of free space available on the device's external storage in megabytes.
getTotalExternalDiskSpaceInMB: Returns the total amount of space available on the device's external storage in megabytes.
getUsedExternalDiskSpaceInMB: Returns the amount of used space on the device's external storage in megabytes.

Get the size of a given directory in MB (megabytes)
String directoryPath = '/storage/emulated/0/Movies/MyFolder/';
double directorySize = await FlutterStorageInfo.getSizeOfDirectoryInMB(directoryPath);
>> 12.98790
copied to clipboard
Get storage type from path (internal or external)
String path = '/storage/emulated/0/Android';
DeviceStorageType storageType = FlutterStorageInfo.getStorageTypeFromPath(path);
>> DeviceStorageType.internal
copied to clipboard
Get storage usage value from total and used space
Get a value from 0.0 to 1.0 indicating the storage usage given the total and used space.
double storageTotal = await FlutterStorageInfo.getExternalStorageTotalSpaceInGB;
double storageUsed = await FlutterStorageInfo.getExternalStorageUsedSpaceInGB;

double storageUsageValue = FlutterStorageInfo.getStorageUsageValue(storageUsed, storageTotal);
>> 0.95
copied to clipboard
Get whether - given the storage type - the storage is below the threshold
This method calls the above methods internally and returns a boolean value indicating whether the storage is below the threshold.
DeviceStorageType storageType = DeviceStorageType.internal;

// Optionally set the threshold. The default is 0.98 (98%)
double threshold = 0.96;

bool isBelowThreshold = FlutterStorageInfo.getIsStorageTypeBelowThreshold(storageType, threshold);
>> true
copied to clipboard
Get whether the storage is low on storage using the storage usage value and threshold
double storageTotal = await FlutterStorageInfo.getExternalStorageTotalSpaceInGB;
double storageUsed = await FlutterStorageInfo.getExternalStorageUsedSpaceInGB;

double threshold = 0.96;
double storageUsageValue = FlutterStorageInfo.getStorageUsageValue(storageUsed, storageTotal);

bool isBelowThreshold = FlutterStorageInfo.getIsStorageBelowThreshold(storageUsageValue, threshold);
>> true
copied to clipboard
Screenshot #

Permissions #
Android #
Add the following permissions to your AndroidManifest.xml file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

</manifest>
copied to clipboard
Supported Platforms #

Android (✅)
iOS (🕑)
Linux (❌)
macOS (❌)
Windows (❌)

Issues and feedback #
Please file issues to send feedback or report a bug. Thank you!

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.