Skip to content

CifarX/flutter_storage_checker

Repository files navigation

storage_checker_plugin

A Flutter plugin to check device storage information such as total, available, and used storage, with human-readable formatting and storage availability checks.

Getting Started

Add this to your pubspec.yaml in the dependencies section:

dependencies:
  storage_checker_plugin:
    git:
      url: https://github.com/CifarX/flutter_storage_checker.git

Then run:

flutter pub get

Usage Example

Here is a complete example of how to use the plugin in your Flutter app:

import 'package:flutter/material.dart';
import 'package:storage_checker_plugin/storage_checker_plugin.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _storageCheckerPlugin = StorageCheckerPlugin();

  int? _fullStorageSize;
  int? _availableStorageSize;
  int? _usedStorageSize;
  bool? _isAvailableStorageSize;
  String? _readableFullStorageSize;
  String? _readableAvailableStorageSize;
  String? _readableUsedStorageSize;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Storage Checker'),
        ),
        body: Center(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text('Full Storage Size: �_fullStorageSize'),
              Text('Available Storage Size: �_availableStorageSize'),
              Text('Used Storage Size: �_usedStorageSize'),
              Text('Is Available Storage for 1000000 bytes �_isAvailableStorageSize'),
              Text('Readable Full Storage Size: �_readableFullStorageSize'),
              Text('Readable Available Storage Size: �_readableAvailableStorageSize'),
              Text('Readable Used Storage Size: �_readableUsedStorageSize'),
            ],
          ),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () async {
            final fullStorageSize = await _storageCheckerPlugin.getFullStorageSize();
            final availableStorageSize = await _storageCheckerPlugin.getAvailableStorageSize();
            final usedStorageSize = await _storageCheckerPlugin.getUsedStorageSize();
            final isAvailableStorageSize = await _storageCheckerPlugin.isAvailableStorageSize(1000000);
            final readableFullStorageSize = await _storageCheckerPlugin.getReadableFullStorageSize();
            final readableAvailableStorageSize = await _storageCheckerPlugin.getReadableAvailableStorageSize();
            final readableUsedStorageSize = await _storageCheckerPlugin.getReadableUsedStorageSize();

            setState(() {
              _fullStorageSize = fullStorageSize;
              _availableStorageSize = availableStorageSize;
              _usedStorageSize = usedStorageSize;
              _isAvailableStorageSize = isAvailableStorageSize;
              _readableFullStorageSize = readableFullStorageSize;
              _readableAvailableStorageSize = readableAvailableStorageSize;
              _readableUsedStorageSize = readableUsedStorageSize;
            });
          },
          tooltip: 'Get Storage Info',
          child: const Icon(Icons.storage),
        ),
      ),
    );
  }
}

For more details, see the example/lib/main.dart file.

API

Method Description Return Type
getFullStorageSize() Returns total storage size in bytes Future<int>
getAvailableStorageSize() Returns available storage size in bytes Future<int>
getUsedStorageSize() Returns used storage size in bytes Future<int>
isAvailableStorageSize(int bytes) Checks if at least bytes are available Future<bool>
getReadableFullStorageSize() Returns total storage size as a string Future<String>
getReadableAvailableStorageSize() Returns available storage size as a string Future<String>
getReadableUsedStorageSize() Returns used storage size as a string Future<String>

Platform Support

  • Android
  • iOS

License

See LICENSE.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors