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

PlatformAndroid

A Flutter plugin to check and manage Android's unused-app auto-reset and hibernation feature for your app.

example/lib/main.dart

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'permission_auto_reset demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        colorSchemeSeed: Colors.indigo,
        useMaterial3: true,
        brightness: Brightness.light,
      ),
      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> {
  RestrictionsStatus? _status;
  bool _loading = true;

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

  Future<void> _refresh() async {
    setState(() => _loading = true);
    final status = await PermissionAutoReset.checkRestrictionsStatus();
    if (!mounted) return;
    setState(() {
      _status = status;
      _loading = false;
    });
  }

  Future<void> _openSettings() async {
    final ok = await PermissionAutoReset.openRestrictionsSettings();
    if (!mounted) return;
    if (!ok) {
      ScaffoldMessenger.of(context).showSnackBar(
        const SnackBar(content: Text('Could not open settings on this device.')),
      );
      return;
    }
    await _refresh();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Permission auto-reset')),
      body: Center(
        child: Padding(
          padding: const EdgeInsets.all(24),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              _StatusCard(status: _status, loading: _loading),
              const SizedBox(height: 24),
              FilledButton.icon(
                onPressed: _loading ? null : _refresh,
                icon: const Icon(Icons.refresh),
                label: const Text('Re-check status'),
              ),
              const SizedBox(height: 8),
              OutlinedButton.icon(
                onPressed: _loading ? null : _openSettings,
                icon: const Icon(Icons.settings),
                label: const Text('Open system settings'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

class _StatusCard extends StatelessWidget {
  const _StatusCard({required this.status, required this.loading});

  final RestrictionsStatus? status;
  final bool loading;

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);

    final (label, color, icon) = switch (status) {
      RestrictionsStatus.enabled => ('Auto-reset ENABLED', Colors.orange, Icons.warning_amber_rounded),
      RestrictionsStatus.disabled => ('Auto-reset disabled', Colors.green, Icons.check_circle),
      RestrictionsStatus.featureNotAvailable => ('Feature not available', Colors.grey, Icons.info_outline),
      RestrictionsStatus.error => ('Error', Colors.red, Icons.error_outline),
      null => ('Checking…', theme.colorScheme.primary, Icons.hourglass_top),
    };

    return Card(
      elevation: 0,
      color: color.withValues(alpha: 0.12),
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
      child: Padding(
        padding: const EdgeInsets.all(20),
        child: Row(
          children: [
            if (loading)
              const SizedBox(
                width: 28,
                height: 28,
                child: CircularProgressIndicator(strokeWidth: 3),
              )
            else
              Icon(icon, size: 28, color: color),
            const SizedBox(width: 16),
            Expanded(
              child: Text(label, style: theme.textTheme.titleMedium),
            ),
          ],
        ),
      ),
    );
  }
}
3
likes
160
points
32
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin to check and manage Android's unused-app auto-reset and hibernation feature for your app.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter

More

Packages that depend on permission_auto_reset

Packages that implement permission_auto_reset