skip to Main Content

i am not getting push notifications in my flutter app

I want to implement push notifications , I have website like CRM and used this website in flutter webview mobile app , website is CRM type where admin can add task for employees and employees can also add their tasks , when task is add for employee then push notification is send to the employee want to implement push notifications in my flutter webview app, please can anyone help me????

2

Answers


  1. Flutter supports Firebase push notification service efficiently in iOS , android , web applications

    https://firebase.google.com/docs/flutter/setup?platform=android

    after firebase setup in flutter app. when adding task you can the below rest api to generate push notification to flutter app

    enter image description here

    Login or Signup to reply.
  2. In your flutter (dart) part;

    import 'package:firebase_messaging/firebase_messaging.dart';
    import 'package:flutter/material.dart';
    
    void main() {
       runApp(MyApp());
     }
    
    class MyApp extends StatelessWidget {
    @override
     Widget build(BuildContext context) {
     return MaterialApp(
      title: 'Push Notification Demo',
      home: HomePage(),
    );
    }
     }
    
    class HomePage extends StatefulWidget {
    @override
    _HomePageState createState() => _HomePageState(); 
    }  
    
    class _HomePageState extends State<HomePage> {
    final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
    
    @override
    void initState() {
    super.initState();
    _firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> message) async {
        print("onMessage: $message");
        showDialog(
          context: context,
          builder: (context) => AlertDialog(
            title: Text('New Task'),
            content: Text(message['notification']['body']),
            actions: <Widget>[
              FlatButton(
                onPressed: () => Navigator.of(context).pop(),
                child: Text('Close'),
              ),
            ],
          ),
        );
       },
       onLaunch: (Map<String, dynamic> message) async {
        print("onLaunch: $message");
        // Handle notification when the app is launched from a terminated state
       },
        onResume: (Map<String, dynamic> message) async {
          print("onResume: $message");
          // Handle notification when the app is resumed from the background
         },
       );
       _firebaseMessaging.requestNotificationPermissions(
      const IosNotificationSettings(sound: true, badge: true, alert: true),
      );
     }
    

    You can use the code above to set up a Flutter app with Firebase Cloud Messaging (FCM) for push notifications. it listens for incoming messages when the app is in the foreground, background, or terminated state and displays them in an alert dialog.

    But dont forget to ensure to follow the Firebase setup instructions and add the required dependencies to your pubspec.yaml file. It’s the most criticla part.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search