Is it possible to check device storage in Flutter?
In order to determine if there is enough device storage to download images, it is possible to check device storage in Flutter without having to do this natively.
Steps to check device storage in Flutter
- Add the
path_provider
package topubspec.yaml
:
dependencies:
path_provider: ^1.6.11
- Import the package:
import 'package:path_provider/path_provider.dart';
- Use the
getExternalStorageDirectory()
method to obtain the root directory of external storage. Then use thelist()
method to get the list of files and folders, and theStat()
method to get the size of a file or folder.
final directory = await getExternalStorageDirectory();
final files = directory.list();
final size = files.stat().size;