shared_storage 0.2.0 copy "shared_storage: ^0.2.0" to clipboard
shared_storage: ^0.2.0 copied to clipboard

outdated

📁 Flutter plugin to get Android shared folders like DCIM, Downloads, Video, Audio. Works with Android 4.1 (API Level 16+)

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:shared_storage/shared_storage.dart';
import 'package:shared_storage_example/persisted_uri_card.dart';

/// TODO: Add examples using [Environment] and [MediaStore] API
void main() => runApp(const Root());

class Root extends StatefulWidget {
  const Root({Key? key}) : super(key: key);

  @override
  _RootState createState() => _RootState();
}

class _RootState extends State<Root> {
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(home: App());
  }
}

class App extends StatefulWidget {
  const App({Key? key}) : super(key: key);

  @override
  _AppState createState() => _AppState();
}

class _AppState extends State<App> {
  List<UriPermission>? persistedPermissionUris;

  @override
  void initState() {
    super.initState();

    _loadPersistedUriPermissions();
  }

  Future<void> _loadPersistedUriPermissions() async {
    persistedPermissionUris = await persistedUriPermissions();

    setState(() => {});
  }

  void _openDocumentTree() async {
    /// Prompt user with a folder picker (Available for Android 5.0+)
    await openDocumentTree();

    /// TODO: Add broadcast listener to be aware when a Uri permission changes
    await _loadPersistedUriPermissions();
  }

  Widget _buildNoFolderAllowedYetWarning() {
    return Padding(
      padding: const EdgeInsets.all(16),
      child: Center(
        child: Text(
          'No folders allowed yet',
          style: TextStyle(
            color: const Color(0xFF000000).withOpacity(.2),
          ),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('SharedStorage Sample'),
      ),
      body: RefreshIndicator(
        onRefresh: _loadPersistedUriPermissions,
        child: CustomScrollView(
          slivers: [
            SliverPadding(
              padding: const EdgeInsets.all(12),
              sliver: SliverList(
                delegate: SliverChildListDelegate(
                  [
                    Center(
                      child: TextButton(
                        onPressed: _openDocumentTree,
                        child: const Text('New allowed folder'),
                      ),
                    ),
                    if (persistedPermissionUris != null)
                      if (persistedPermissionUris!.isEmpty)
                        _buildNoFolderAllowedYetWarning()
                      else
                        for (final permissionUri in persistedPermissionUris!)
                          PersistedUriCard(
                            permissionUri: permissionUri,
                            onChange: _loadPersistedUriPermissions,
                          )
                    else
                      const Text('Loading...'),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
58
likes
0
pub points
93%
popularity

Publisher

verified publisheralexrintt.io

📁 Flutter plugin to get Android shared folders like DCIM, Downloads, Video, Audio. Works with Android 4.1 (API Level 16+)

Repository (GitHub)
View/report issues

Documentation

Documentation

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on shared_storage