storage_space 1.0.1+5 copy "storage_space: ^1.0.1+5" to clipboard
storage_space: ^1.0.1+5 copied to clipboard

PlatformAndroidiOS
outdated

Get the free, available and total storage space for the device. Utility helpers for readable sizes

example/lib/main.dart

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

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  StorageSpace? _storageSpace;

  @override
  void initState() {
    super.initState();
    initStorageSpace();
  }

  void initStorageSpace() async {
    StorageSpace storageSpace = await getStorageSpace(
      lowOnSpaceThreshold: 2 * 1024 * 1024 * 1024, // 2GB
      fractionDigits: 1,
    );
    setState(() {
      _storageSpace = storageSpace;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Storage Space'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Stack(
                alignment: Alignment.center,
                children: <Widget>[
                  SizedBox(
                    height: 200,
                    width: 200,
                    child: CircularProgressIndicator(
                      strokeWidth: 20,
                      value: _storageSpace?.usageValue ?? null,
                      backgroundColor: Colors.grey.shade200,
                      valueColor: AlwaysStoppedAnimation<Color>(
                        (_storageSpace?.lowOnSpace ?? false)
                            ? Colors.red
                            : Theme.of(context).primaryColor,
                      ),
                    ),
                  ),
                  if (_storageSpace == null) ...[
                    Text(
                      'Loading',
                      style: Theme.of(context).textTheme.headline4,
                    ),
                  ],
                  if (_storageSpace != null) ...[
                    Column(
                      children: [
                        Text(
                          '${_storageSpace?.freeSize}',
                          style: Theme.of(context).textTheme.headline3,
                        ),
                        if (_storageSpace?.lowOnSpace != true) ...[
                          Text(
                            'Remaining',
                            style: Theme.of(context).textTheme.headline6,
                          ),
                        ],
                        if (_storageSpace?.lowOnSpace == true) ...[
                          Text(
                            'Low On Space',
                            style: Theme.of(context).textTheme.headline6,
                          ),
                        ],
                      ],
                    ),
                  ],
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}
20
likes
160
points
7.99k
downloads

Publisher

verified publisheroodavid.com

Weekly Downloads

Get the free, available and total storage space for the device. Utility helpers for readable sizes

Repository (GitHub)

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on storage_space