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

A Flutter package to get information about the disk capacity of Android and iOS devices.

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:disk_capacity/disk_capacity.dart';

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

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

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

class _MyAppState extends State<MyApp> {
  double _freeDiskSpace = 0.0;
  double _totalDiskSpace = 0.0;
  String _error = '';
  final _DiskCapacityPlugin = DiskCapacity();

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

  Future<void> initPlatformState() async {
    double freeDiskSpace = 0.0;
    double totalDiskSpace = 0.0;

    try {
      freeDiskSpace = await _DiskCapacityPlugin.getFreeDiskSpace();
      totalDiskSpace = await _DiskCapacityPlugin.getTotalDiskSpace();
    } on PlatformException {
      setState(() {
        _error = 'Failed to get disk space.';
      });
    }

    setState(() {
      _freeDiskSpace = freeDiskSpace;
      _totalDiskSpace = totalDiskSpace;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('Free disk space: $_freeDiskSpace Mo'),
            Text('Total disk space: $_totalDiskSpace Mo'),
            if (_error.isNotEmpty) ...[
              Text(_error),
              const SizedBox(height: 20.0),
            ],
          ],
        ),
      ),
    );
  }
}
1
likes
160
points
23
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package to get information about the disk capacity of Android and iOS devices.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on disk_capacity

Packages that implement disk_capacity