flutter_absolute_path_provider 0.1.0 copy "flutter_absolute_path_provider: ^0.1.0" to clipboard
flutter_absolute_path_provider: ^0.1.0 copied to clipboard

A Flutter plugin that exposes absolute paths of common system directories on Android and iOS.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_absolute_path_provider/flutter_absolute_path_provider.dart';

void main() => runApp(const AbsolutePathDemoApp());

class AbsolutePathDemoApp extends StatelessWidget {
  const AbsolutePathDemoApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Absolute path provider',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(colorSchemeSeed: Colors.indigo, useMaterial3: true),
      darkTheme: ThemeData(
        colorSchemeSeed: Colors.indigo,
        useMaterial3: true,
        brightness: Brightness.dark,
      ),
      home: const _HomeScreen(),
    );
  }
}

class _HomeScreen extends StatefulWidget {
  const _HomeScreen();

  @override
  State<_HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<_HomeScreen> {
  final Map<DirectoryType, String> _paths = {};
  DirectoryType? _busy;

  Future<void> _load(DirectoryType type) async {
    setState(() => _busy = type);
    try {
      final dir = await AbsolutePath.absoluteDirectory(dirType: type);
      if (!mounted) return;
      if (dir == null) {
        _toast('Directory not available for ${type.value}');
        return;
      }
      setState(() => _paths[type] = dir.path);
    } on DirectoryException catch (e) {
      _toast(e.message);
    } finally {
      if (mounted) setState(() => _busy = null);
    }
  }

  void _toast(String message) {
    ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(message)));
  }

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    return Scaffold(
      appBar: AppBar(title: const Text('Absolute path provider')),
      body: SafeArea(
        child: Padding(
          padding: const EdgeInsets.all(16),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              if (!AbsolutePath.isPlatformSupported)
                _Banner(
                  color: theme.colorScheme.errorContainer,
                  text: 'This platform is not supported by the plugin.',
                ),
              Text('Tap a directory to resolve its absolute path:',
                  style: theme.textTheme.titleMedium),
              const SizedBox(height: 12),
              Wrap(
                spacing: 8,
                runSpacing: 8,
                children: [
                  for (final type in DirectoryType.values)
                    FilterChip(
                      label: Text(type.value),
                      selected: _paths.containsKey(type),
                      onSelected: AbsolutePath.isPlatformSupported && _busy == null
                          ? (_) => _load(type)
                          : null,
                    ),
                ],
              ),
              const SizedBox(height: 16),
              const Divider(),
              Expanded(
                child: _paths.isEmpty
                    ? Center(
                        child: Text(
                          'No paths resolved yet.',
                          style: theme.textTheme.bodyMedium?.copyWith(
                            color: theme.colorScheme.onSurfaceVariant,
                          ),
                        ),
                      )
                    : ListView(
                        children: [
                          for (final entry in _paths.entries)
                            Card(
                              elevation: 0,
                              child: ListTile(
                                title: Text(entry.key.value),
                                subtitle: Text(entry.value),
                                trailing: IconButton(
                                  tooltip: 'Copy',
                                  icon: const Icon(Icons.copy),
                                  onPressed: () async {
                                    await Clipboard.setData(ClipboardData(text: entry.value));
                                    if (!mounted) return;
                                    _toast('Path copied');
                                  },
                                ),
                              ),
                            ),
                        ],
                      ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

class _Banner extends StatelessWidget {
  const _Banner({required this.color, required this.text});
  final Color color;
  final String text;

  @override
  Widget build(BuildContext context) => Container(
        margin: const EdgeInsets.only(bottom: 12),
        padding: const EdgeInsets.all(12),
        decoration: BoxDecoration(color: color, borderRadius: BorderRadius.circular(12)),
        child: Text(text),
      );
}
2
likes
160
points
40
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin that exposes absolute paths of common system directories on Android and iOS.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on flutter_absolute_path_provider

Packages that implement flutter_absolute_path_provider