flutter_absolute_path_provider 0.0.1
flutter_absolute_path_provider: ^0.0.1 copied to clipboard
A package that folders directories (absolute path) from Android and iOS device.
flutter_absolute_path_provider #
A Flutter plugin for accessing directory paths across Android and iOS platforms. This plugin provides a simple and efficient way to access various system (absolute) directories like Downloads, Documents, Pictures, and more.
Features #
- Access system directory paths (Downloads, Documents, Pictures, etc.)
- Comprehensive error handling
- Platform-specific path handling
Getting Started #
Add flutter_absolute_path_provider to your pubspec.yaml:
dependencies:
flutter_absolute_path_provider: ^1.0.0
Usage #
Import the package #
import 'package:flutter_absolute_path_provider/flutter_absolute_path_provider.dart';
Basic Operations #
// Get downloads directory
Directory? downloadsDir = await AbsolutePath.absoluteDirectory(
dirType: DirectoryType.downloads
);
// Get pictures directory
Directory? picturesDir = await AbsolutePath.absoluteDirectory(
dirType: DirectoryType.pictures
);
// Create a custom directory
Directory? customDir = await AbsolutePath.absoluteDirectory(
dirType: DirectoryType.documents
);
await customDir?.createIfNotExists();
// Check if directory is writable
bool isWritable = await customDir?.isWritable ?? false;
Directory Types #
enum DirectoryType {
alarms,
audioBooks,
dcim,
documents,
downloads,
movies,
music,
notifications,
pictures,
podcasts,
recordings,
ringtones,
screenshots
}
Directory Utilities #
// Create directory if not exists
Directory dir = await directory.createIfNotExists();
// Check if directory is writable
bool canWrite = await directory.isWritable;
// Ensure directory is ready for use
await directory.ensureWritable();
// Get directory size
int size = await DirectoryUtils.getDirectorySize(directory);
String readableSize = DirectoryUtils.formatSize(size);
Error Handling #
The plugin includes comprehensive error handling:
try {
final dir = await AbsolutePath.absoluteDirectory(
dirType: DirectoryType.downloads
);
await dir?.ensureWritable();
} on DirectoryException catch (e) {
print('Directory error: ${e.message}');
if (e.code == 'PERMISSION_DENIED') {
// Handle permission error
}
} catch (e) {
print('Unexpected error: $e');
}
Directory Model #
class Directory {
String path;
Future<bool> exists();
Future<Directory> create({bool recursive = false});
Future<bool> get isWritable;
Future<void> ensureWritable();
Stream<FileSystemEntity> list({bool recursive = false});
}
Additional Notes #
- This plugin does not handle permission requesting. Use plugins like
permission_handlerto manage storage permissions. - iOS access is limited to app-specific directories for security reasons.
- The plugin automatically handles platform-specific path differences.
Contributing #
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Support #
If you find this plugin helpful, consider supporting me: