FileHandler class

A utility class for handling file operations with native platform integration.

This class provides methods for downloading files, managing storage permissions, and handling file operations in a platform-agnostic way.

Features

  • File downloads with progress tracking
  • Storage permission handling
  • Cross-platform file system operations
  • No third-party dependencies

Usage

// Download a file
final filePath = await FileHandler.downloadFile(
  url: 'https://example.com/file.pdf',
  fileName: 'document.pdf',
  directory: await FileHandler.getApplicationDocumentsDirectory(),
  onProgress: (progress) {
    print('Download progress: $progress%');
  },
);

// Save bytes to a file
final success = await FileHandler.saveFile(
  bytes: myBytes,
  fileName: 'data.bin',
  directory: await FileHandler.getTemporaryDirectory(),
);

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

deleteFile(String filePath) Future<bool>
Deletes a file at the given path.
downloadFile({required String url, required String fileName, required String directory, void onProgress(double progress)?}) Future<String?>
Downloads a file from the given URL and saves it to the specified directory.
fileExists(String filePath) Future<bool>
Checks if a file exists at the given path.
getApplicationDocumentsDirectory() Future<String>
Gets the application documents directory path.
getTemporaryDirectory() Future<String>
Gets the temporary directory path.
requestStoragePermission() Future<bool>
Requests storage permissions on Android.
saveFile({required List<int> bytes, required String fileName, required String directory}) Future<bool>
Saves bytes to a file at the specified path.