Coder Social home page Coder Social logo

correct-syntax / get_storage_info Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 75 KB

A Flutter plugin to get information about storage on Android

Home Page: https://pub.dev/packages/get_storage_info

License: MIT License

Kotlin 56.37% Dart 43.63%
android dart flutter flutter-package flutter-plugin android-storage

get_storage_info's Introduction

get_storage_info

A Flutter plugin to get information about storage on Android. Get free, used, and total internal and external (SD card) storage space, and more.

This is a friendly fork of storage_info.

Installing

Add get_storage_info to your pubspec.yaml:

dependencies:
  get_storage_info: ^0.2.1

Usage

Importing

import 'package:get_storage_info/get_storage_info.dart';

Using the methods

All methods can be statically accessed via the GetStorageInfo class.

Get internal storage info

// Get internal storage total space in bytes, MB and GB
await StorageInfo.getStorageTotalSpace; // return int
await StorageInfo.getStorageTotalSpaceInMB; // return double
await StorageInfo.getStorageTotalSpaceInGB; // return double

// Get internal storage free space in bytes, MB and GB
await StorageInfo.getStorageFreeSpace; // return int
await StorageInfo.getStorageFreeSpaceInMB; // return double
await StorageInfo.getStorageFreeSpaceInGB; // return double

// Get internal storage used space in bytes, MB and GB
await StorageInfo.getStorageUsedSpace; // return int
await StorageInfo.getStorageUsedSpaceInMB; // return double
await StorageInfo.getStorageUsedSpaceInGB; // return double

Get external (SD card) storage info

// Get external storage total space in bytes, MB, and GB
return await StorageInfo.getExternalStorageTotalSpace; // return int
return await StorageInfo.getExternalStorageTotalSpaceInMB; // return double
return await StorageInfo.getExternalStorageTotalSpaceInGB; // return double

// Get external storage free space in bytes, MB, and GB
return await StorageInfo.getExternalStorageFreeSpace; // return int
return await StorageInfo.getExternalStorageFreeSpaceInMB; // return double
return await StorageInfo.getExternalStorageFreeSpaceInGB; // return double

// Get external storage used space in bytes, MB, and GB
return await StorageInfo.getExternalStorageUsedSpace; // return int
return await StorageInfo.getExternalStorageUsedSpaceInMB; // return double
return await StorageInfo.getExternalStorageUsedSpaceInGB; // return double

Get the size of a given directory in MB

String directoryPath = '/storage/emulated/0/Movies/MyFolder/';
double directorySize = await GetStorageInfo.getSizeOfDirectoryInMB(directoryPath);
>> 12.98790

Get storage type from path

String path = '/storage/emulated/0/Android';
DeviceStorageType storageType = GetStorageInfo.getStorageTypeFromPath(path);
>> DeviceStorageType.internal

Get storage usage value

Get a value from 0.0 to 1.0 representing the storage usage. Useful for storage indicators.

double storageTotal = await GetStorageInfo.getExternalStorageTotalSpaceInGB;
double storageUsed = await GetStorageInfo.getExternalStorageUsedSpaceInGB;

double storageUsageValue = GetStorageInfo.getStorageUsageValue(storageUsed, storageTotal);
>> 0.95

Get whether the storage type is low on storage

This method calls the above methods internally to get the storage info, so if you already get the info in your code it may be more optimized to use getIsStorageBelowThreshold instead.

DeviceStorageType storageType = DeviceStorageType.internal;

// Optionally set the threshold. The default is 500MB.
double threshold = 600.0;

bool isLowOnStorage = await GetStorageInfo.getIsLowOnStorage(storageType, threshold);
>> false

Get whether the storage is below the low storage threshold

double threshold = 600.0; // in MB
double storageFree = await GetStorageInfo.getExternalStorageFreeSpaceInMB;

bool isBelowThreshold = GetStorageInfo.getIsStorageBelowThreshold(storageFree, threshold);
>> true

get_storage_info's People

Contributors

correct-syntax avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.