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

PlatformAndroid

Android implementation of the storage_utility plugin.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:path_provider/path_provider.dart';
import 'package:storage_utility_platform_interface/storage_utility_platform_interface.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 StorageUtilityPlatform utility = StorageUtilityPlatform.instance;
  final NumberFormat _format = NumberFormat.decimalPattern();

  String? _docPath;
  int? _totalBytes;
  int? _freeBytes;

  void getTotalBytes() {
    utility
        .getTotalBytes(path: _docPath!)
        .then((value) => setState(() => _totalBytes = value));
  }

  void getFreeBytes() {
    utility
        .getFreeBytes(path: _docPath!)
        .then((value) => setState(() => _freeBytes = value));
  }

  @override
  void initState() {
    super.initState();
    getApplicationDocumentsDirectory().then((value) {
      setState(() {
        _docPath = value.path;
      });
      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'),
            const SizedBox(height: 16),
            Text('Free Bytes: ${_format.format(_freeBytes ?? 0)} bytes'),
            const SizedBox(height: 32),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                ElevatedButton(
                    onPressed: _docPath == null ? null : getTotalBytes,
                    child: const Text('getTotalBytes')),
                const SizedBox(width: 16),
                ElevatedButton(
                  onPressed: _docPath == null ? null : getFreeBytes,
                  child: const Text('getFreeBytes'),
                ),
              ],
            )
          ],
        ),
      ),
    );
  }
}
0
likes
160
points
11.4k
downloads

Publisher

verified publisherdeephow.com

Weekly Downloads

Android implementation of the storage_utility plugin.

Repository (GitHub)

Topics

#disk #storage

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

flutter, storage_utility_platform_interface

More

Packages that depend on storage_utility_android