notification_cleaner 0.0.4 copy "notification_cleaner: ^0.0.4" to clipboard
notification_cleaner: ^0.0.4 copied to clipboard

Programmatically clear all notifications from the system tray with this lightweight Flutter plugin. Supports modern Android and iOS implementations with a simple, minimal API.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:notification_cleaner/notification_cleaner.dart';
import 'package:permission_handler/permission_handler.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        useMaterial3: true,
        colorSchemeSeed: Colors.deepPurple,
      ),
      home: const HomeScreen(),
    );
  }
}

class HomeScreen extends StatefulWidget {
  const HomeScreen({super.key});

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

class _HomeScreenState extends State<HomeScreen> {
  bool _isClearing = false;

  Future<void> _handleClearNotifications() async {
    setState(() => _isClearing = true);

    try {
      // Handle Android 13+ notification permission
      if (await Permission.notification.isDenied) {
        await Permission.notification.request();
      }

      await NotificationCleaner.clearAllNotifications();
      
      if (mounted) {
        ScaffoldMessenger.of(context).showSnackBar(
          const SnackBar(content: Text('Notifications cleared successfully!')),
        );
      }
    } catch (e) {
      if (mounted) {
        ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(content: Text('Error: $e'), backgroundColor: Colors.red),
        );
      }
    } finally {
      if (mounted) {
        setState(() => _isClearing = false);
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Notification Cleaner'),
        centerTitle: true,
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Icon(
              Icons.notifications_off_outlined,
              size: 100,
              color: Colors.deepPurple,
            ),
            const SizedBox(height: 24),
            const Padding(
              padding: EdgeInsets.symmetric(horizontal: 32),
              child: Text(
                'Press the button below to clear all active notifications from your device.',
                textAlign: TextAlign.center,
                style: TextStyle(fontSize: 16),
              ),
            ),
            const SizedBox(height: 48),
            _isClearing
                ? const CircularProgressIndicator()
                : ElevatedButton.icon(
                    onPressed: _handleClearNotifications,
                    icon: const Icon(Icons.delete_sweep),
                    label: const Text('Clear All Notifications'),
                    style: ElevatedButton.styleFrom(
                      padding: const EdgeInsets.symmetric(
                        horizontal: 32,
                        vertical: 16,
                      ),
                    ),
                  ),
          ],
        ),
      ),
    );
  }
}
0
likes
150
points
65
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Programmatically clear all notifications from the system tray with this lightweight Flutter plugin. Supports modern Android and iOS implementations with a simple, minimal API.

Repository (GitHub)
View/report issues

Topics

#notifications #flutter-plugin #android

License

MIT (license)

Dependencies

flutter, permission_handler

More

Packages that depend on notification_cleaner

Packages that implement notification_cleaner