storage_utility 1.0.0 copy "storage_utility: ^1.0.0" to clipboard
storage_utility: ^1.0.0 copied to clipboard

Flutter plugin for getting storage information on host platform, such as available space and total space.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:storage_utility/storage_utility.dart' as storage;

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

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

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

class _MyAppState extends State<MyApp> {
  final NumberFormat _format = NumberFormat.decimalPattern();
  int? _totalBytes;
  int? _freeBytes;

  Future<void> getTotalBytes() async {
    storage
        .getTotalBytes()
        .then((value) => setState(() => _totalBytes = value));
  }

  void getFreeBytes() {
    storage.getFreeBytes().then((value) => setState(() => _freeBytes = value));
  }

  @override
  void initState() {
    super.initState();
    getTotalBytes();
    getFreeBytes();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Storage Utility Example App'),
        ),
        body: Column(
          children: [
            const SizedBox(height: 32),
            Text('Total Bytes: ${_format.format(_totalBytes ?? 0)} bytes'),
            Text(
              '(${storage.formatBytes(_totalBytes ?? 0)})',
              style: const TextStyle(color: Colors.grey),
            ),
            const SizedBox(height: 16),
            Text('Free Bytes: ${_format.format(_freeBytes ?? 0)} bytes'),
            Text(
              '(${storage.formatBytes(_freeBytes ?? 0)})',
              style: const TextStyle(color: Colors.grey),
            ),
            const SizedBox(height: 32),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                ElevatedButton(
                    onPressed: getTotalBytes,
                    child: const Text('getTotalBytes')),
                const SizedBox(width: 16),
                ElevatedButton(
                  onPressed: getFreeBytes,
                  child: const Text('getFreeBytes'),
                ),
              ],
            )
          ],
        ),
      ),
    );
  }
}
4
likes
160
points
11.4k
downloads

Publisher

verified publisherdeephow.com

Weekly Downloads

Flutter plugin for getting storage information on host platform, such as available space and total space.

Repository (GitHub)

Topics

#disk #storage

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

flutter, path_provider, storage_utility_android, storage_utility_foundation, storage_utility_platform_interface, storage_utility_windows

More

Packages that depend on storage_utility