flutter_permission_auto_return 0.0.1 copy "flutter_permission_auto_return: ^0.0.1" to clipboard
flutter_permission_auto_return: ^0.0.1 copied to clipboard

discontinuedreplaced by: permission_handler_auto_back

Wrapper around permission_handler that adds automatic return-to-app on Android after the user grants special permissions from the system Settings page (e.g. all-files access, overlay, location-always).

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_permission_auto_return/flutter_permission_auto_return.dart';

void main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Permission Auto-Return Demo',
      theme: ThemeData(useMaterial3: true, colorSchemeSeed: Colors.indigo),
      home: const _DemoPage(),
    );
  }
}

class _DemoEntry {
  const _DemoEntry(this.label, this.permission, {this.note});

  final String label;
  final Permission permission;
  final String? note;
}

class _DemoPage extends StatefulWidget {
  const _DemoPage();

  @override
  State<_DemoPage> createState() => _DemoPageState();
}

class _DemoPageState extends State<_DemoPage> {
  final Map<Permission, PermissionStatus> _statuses = {};

  static const List<_DemoEntry> _entries = [
    _DemoEntry('Camera', Permission.camera),
    _DemoEntry('Microphone', Permission.microphone),
    _DemoEntry('Location (when in use)', Permission.locationWhenInUse),
    _DemoEntry(
      'Location (always)',
      Permission.locationAlways,
      note: 'Special — opens app details on Android, auto-returns on grant.',
    ),
    _DemoEntry('Notification', Permission.notification),
    _DemoEntry(
      'All files access',
      Permission.manageExternalStorage,
      note: 'Special — opens "All files access" page, auto-returns on toggle.',
    ),
    _DemoEntry(
      'Display over other apps',
      Permission.systemAlertWindow,
      note: 'Special — opens overlay settings, auto-returns on toggle.',
    ),
    _DemoEntry(
      'Schedule exact alarm',
      Permission.scheduleExactAlarm,
      note: 'Special on Android 12+.',
    ),
    _DemoEntry('Contacts', Permission.contacts),
    _DemoEntry('Photos', Permission.photos),
  ];

  Future<void> _request(_DemoEntry entry) async {
    final status = await entry.permission.requestWithAutoReturn();
    if (!mounted) return;
    setState(() => _statuses[entry.permission] = status);
  }

  Future<void> _refresh(_DemoEntry entry) async {
    final status = await entry.permission.status;
    if (!mounted) return;
    setState(() => _statuses[entry.permission] = status);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Permission Auto-Return')),
      body: ListView.separated(
        padding: const EdgeInsets.all(12),
        itemCount: _entries.length,
        separatorBuilder: (_, _) => const SizedBox(height: 8),
        itemBuilder: (context, i) {
          final e = _entries[i];
          final status = _statuses[e.permission];
          return Card(
            child: ListTile(
              title: Text(e.label),
              subtitle: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text('Status: ${status?.name ?? "unknown"}'),
                  if (e.note != null)
                    Padding(
                      padding: const EdgeInsets.only(top: 4),
                      child: Text(
                        e.note!,
                        style: Theme.of(context).textTheme.bodySmall,
                      ),
                    ),
                ],
              ),
              trailing: Wrap(
                spacing: 4,
                children: [
                  IconButton(
                    icon: const Icon(Icons.refresh),
                    tooltip: 'Refresh status',
                    onPressed: () => _refresh(e),
                  ),
                  FilledButton(
                    onPressed: () => _request(e),
                    child: const Text('Request'),
                  ),
                ],
              ),
            ),
          );
        },
      ),
    );
  }
}
12
likes
0
points
189
downloads

Publisher

unverified uploader

Weekly Downloads

Wrapper around permission_handler that adds automatic return-to-app on Android after the user grants special permissions from the system Settings page (e.g. all-files access, overlay, location-always).

Repository (GitHub)
View/report issues

Topics

#permissions #permission-handler #android #settings #auto-return

License

unknown (license)

Dependencies

flutter, permission_handler

More

Packages that depend on flutter_permission_auto_return

Packages that implement flutter_permission_auto_return