A Flutter plugin to get total and available device storage information for iOS and Android devices.
dependencies:
storage_info: ^0.1.0+1Import the package:
import 'package:storage_info/storage_info.dart';Get storage information:
Future<void> getStorageInfo() async {
try {
final storageInfo = StorageInfo();
final info = await storageInfo.getStorageInfo();
print('Total storage: ${info.totalBytes} bytes');
print('Free storage: ${info.freeBytes} bytes');
print('Used storage: ${info.usedBytes} bytes');
print('Used percentage: ${info.usedPercentage * 100}%');
print('Free percentage: ${info.freePercentage * 100}%');
} catch (e) {
print('Error: $e');
}
}| Android | iOS |
|---|---|
| ✅ | ✅ |
For Android, the plugin requires READ_EXTERNAL_STORAGE permission. Add the following to your AndroidManifest.xml:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />Also, for devices running Android 6.0 (API level 23) and above, you'll need to request the permission at runtime:
import 'package:permission_handler/permission_handler.dart';
Future<void> getStorageWithPermission() async {
var status = await Permission.storage.status;
if (!status.isGranted) {
status = await Permission.storage.request();
if (!status.isGranted) {
// Handle permission not granted
return;
}
}
// Now you can call getStorageInfo
final info = await StorageInfo().getStorageInfo();
// ...
}Note: The permission_handler package is not included in this package and needs to be added separately if you want to handle runtime permissions.
- Get total device storage in bytes
- Get available/free storage in bytes
- Get used storage in bytes
- Calculate percentage of used and free storage
❗ In order to start using Storage Info you must have the Flutter SDK installed on your machine.
Install via flutter pub add:
dart pub add storage_infoStorage Info comes with a built-in GitHub Actions workflow powered by Very Good Workflows but you can also add your preferred CI/CD solution.
Out of the box, on each pull request and push, the CI formats, lints, and tests the code. This ensures the code remains consistent and behaves correctly as you add functionality or make changes. The project uses Very Good Analysis for a strict set of analysis options used by our team. Code coverage is enforced using the Very Good Workflows.
For first time users, install the very_good_cli:
dart pub global activate very_good_cliTo run all unit tests:
very_good test --coverageTo view the generated coverage report you can use lcov.
# Generate Coverage Report
genhtml coverage/lcov.info -o coverage/
# Open Coverage Report
open coverage/index.html