masamune_notification_firebase 1.2.60 copy "masamune_notification_firebase: ^1.2.60" to clipboard
masamune_notification_firebase: ^1.2.60 copied to clipboard

outdated

Package for receiving PUSH notifications using Firebase Messaging. Firebase Functions can also be used to send notifications.

example/lib/main.dart

// Flutter imports:
import 'package:flutter/material.dart';

// Package imports:
import 'package:masamune/masamune.dart';
import 'package:masamune_notification_firebase/masamune_notification_firebase.dart';

const pushNotificationAdapter = PushNotificationMasamuneAdapter(
  androidNotificationChannelId: "masamune_firebase_messaging_channel",
  androidNotificationChannelTitle: "Important Notification",
  androidNotificationChannelDescription:
      "This notification channel is used for important notifications.",
);

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

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

  @override
  Widget build(BuildContext context) {
    return MasamuneApp(
      home: const NotificationPage(),
      title: "Flutter Demo",
      masamuneAdapters: const [pushNotificationAdapter],
      theme: AppThemeData(
        primary: Colors.blue,
      ),
    );
  }
}

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

  @override
  State<StatefulWidget> createState() => NotificationPageState();
}

class NotificationPageState extends State<NotificationPage> {
  final notification = PushNotification();

  @override
  void initState() {
    super.initState();
    notification.listen();
    notification.addListener(_handledOnUpdate);
  }

  void _handledOnUpdate() {
    setState(() {});
  }

  @override
  void dispose() {
    super.dispose();
    notification.removeListener(_handledOnUpdate);
    notification.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("App Demo")),
      body: ListView(
        children: [
          if (notification.value != null) ...[
            ListTile(
              title: Text(notification.value!.title),
            ),
            ListTile(
              title: Text(notification.value!.text),
            ),
          ],
        ],
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () async {
          await notification.send(
            title: "Notification",
            text: "Notification text",
            target: "Topic Name",
          );
        },
        child: const Icon(Icons.person),
      ),
    );
  }
}
1
likes
140
points
63
downloads

Publisher

verified publishermathru.net

Weekly Downloads

Package for receiving PUSH notifications using Firebase Messaging. Firebase Functions can also be used to send notifications.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

firebase_messaging, flutter, flutter_local_notifications, katana_firebase, masamune

More

Packages that depend on masamune_notification_firebase