firebase_notifications_handler 1.0.1 copy "firebase_notifications_handler: ^1.0.1" to clipboard
firebase_notifications_handler: ^1.0.1 copied to clipboard

outdated

Simple notifications handler which provides callbacks like onTap which really make it easy to handle notification taps and a lot more.

example/lib/main.dart

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

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  // TODO: add firebase_core and call
  // await Firebase.initializeApp();
  runApp(_MainApp());
}

String? fcmToken;

class _MainApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorKey: FirebaseNotificationsHandler.navigatorKey,
      home: const HomeScreen(),
    );
  }
}

class HomeScreen extends StatelessWidget {
  const HomeScreen({
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return FirebaseNotificationsHandler(
      onOpenNotificationArrive: (_, payload) {
        debugPrint(
          "Notification received while app is open with payload $payload",
        );
      },
      onTap: (navigatorState, appState, payload) {
        debugPrint("Notification tapped with $appState & payload $payload");

        navigatorState.currentState!.pushNamed('newRouteName');
        // OR
        final context = navigatorState.currentContext!;
        Navigator.pushNamed(context, 'newRouteName');
      },
      onFCMTokenInitialize: (_, token) => fcmToken = token,
      onFCMTokenUpdate: (_, token) {
        fcmToken = token;
        // await User.updateFCM(token);
      },
      child: SafeArea(
        child: Scaffold(
          body: Center(
            child: Text(
              '_HomeScreen',
              style: Theme.of(context).textTheme.headline3,
            ),
          ),
        ),
      ),
    );
  }
}
31
likes
0
pub points
83%
popularity

Publisher

verified publisherrithik-dev.me

Simple notifications handler which provides callbacks like onTap which really make it easy to handle notification taps and a lot more.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

firebase_messaging, flutter, flutter_local_notifications, http, path_provider

More

Packages that depend on firebase_notifications_handler