fcm_eraser_plus 1.1.3 copy "fcm_eraser_plus: ^1.1.3" to clipboard
fcm_eraser_plus: ^1.1.3 copied to clipboard

The plugin has been upgraded and extended with additional features for working with FCM

example/lib/main.dart

import 'dart:developer';
import 'dart:io';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:fcm_eraser_plus/fcm_eraser_plus.dart';
import 'fcm_services/fcm_service.dart';
import 'firebase_options.dart';
import 'widgets/base_button.dart';

@pragma('vm:entry-point')
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
}

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );

  FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);

  runApp(const MyApp());
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _fcmEraserPlusPlugin = FcmEraserPlus.instance;
  final _fcmService = FcmService.instance;

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

    _initFCMService();
  }

  Future<void> _initFCMService() async {
    await _fcmService.requestPermission();
    await _fcmService.initialize();
  }

  Future<void> _getFcmToken() async {
    final token = await _fcmService.getToken();

    log('FCM Token:\n$token');
  }

  Future<void> _clearAll() async {
    await _fcmEraserPlusPlugin.clearAllNotifications();
  }

  Future<void> _clearByTags({required List<String> tags}) async {
    await _fcmEraserPlusPlugin.clearByTags(tags: tags);
  }

  Future<void> _getActiveTags() async {
    final activeTags = await _fcmEraserPlusPlugin.getActiveTags();

    log('Active tags:\n$activeTags');
  }

  Future<void> _setBadge({required int count, bool isClear = true}) async {
    await _fcmEraserPlusPlugin.setBadge(count: count, isClear: isClear);
  }

  @override
  Widget build(BuildContext context) {
    final width = MediaQuery.of(context).size.width;
    final height = MediaQuery.of(context).size.width;

    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.blueAccent,
          centerTitle: true,
          title: const Text(
            'FCM Eraser Plus',
            style: TextStyle(
              color: Colors.white,
            ),
          ),
        ),
        body: Container(
          padding: const EdgeInsets.all(15),
          width: width,
          height: height,
          child: Column(
            children: [
              BaseButton(
                label: 'Get FCM Token',
                onTap: _getFcmToken,
              ),
              const SizedBox(height: 20),
              BaseButton(
                label: 'Clear all notifications',
                onTap: _clearAll,
              ),
              const SizedBox(height: 20),
              BaseButton(
                label: 'Clear with tags',
                onTap: () async => _clearByTags(
                  tags: ['7BE7A275-E0A3-4DDD-A3BB-14A82ED0BD18'],
                ),
              ),
              const SizedBox(height: 20),
              BaseButton(
                label: 'Get active tags',
                onTap: _getActiveTags,
              ),
              Visibility(
                visible: Platform.isIOS,
                child: Column(
                  children: [
                    const SizedBox(height: 20),
                    BaseButton(
                      label: 'Set count badge',
                      onTap: () async => _setBadge(count: 9),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
3
likes
160
points
16
downloads

Publisher

verified publishertechmind.io.vn

Weekly Downloads

The plugin has been upgraded and extended with additional features for working with FCM

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on fcm_eraser_plus

Packages that implement fcm_eraser_plus