skip to Main Content

I am using Flutter WebRTC for doing video calls. The video call is working fine. For getting the video call when app is running background or app is closed I am using Firebase Cloud Messaging and I am using firebase messaging package. I am getting the push notification while app is closed and running background. But I am unable to show a dialog like Whatsapp/ Skype/ Messenger notification dialog. I am using flutter local notification package for showing push notification.
enter image description here
I want to show a dialog shown in the picture.

Also, when the app is closed, if the push notification is clicked, I want to redirect to a desired page. At this moment it is redirecting to splash screen, then home screen, at last to desired screen. How can I redirect at first?

2

Answers


  1. You can use firebase_messaging and awesome_notifications

    add this in your firebase background subscription handler

    await AwesomeNotifications().createNotification(
      content: NotificationContent(
        id: createuniqueId(),
        channelKey: 'basic_channel',
        title: message.data['title'],
        body: message.data['body'],
        wakeUpScreen: true,
        fullScreenIntent: true,
        autoDismissible: false,
        category: NotificationCategory.Call,
        locked: true,
        displayOnForeground: true,
      ),
      actionButtons: [
        NotificationActionButton(
          key: 'accept',
          label: 'Accept',
        ),
        NotificationActionButton(
          isDangerousOption: true,
          key: 'reject',
          label: 'Reject',
        ),
      ],
    );
    

    add this in your main()

    AwesomeNotifications().initialize(
        'resource://drawable/ic_icon',
        [
          NotificationChannel(
            channelKey: 'basic_channel', 
            channelName: 'Basic Notification', 
            channelDescription: 'Hello world',
            importance: NotificationImportance.High,
            channelShowBadge: true,
            vibrationPattern: highVibrationPattern
          ),
        ]
      );
    
    Login or Signup to reply.
  2. Example for flutter_local_notifications :

    android

    Future<void> _showNotificationWithActions() async {
      const AndroidNotificationDetails androidNotificationDetails =
          AndroidNotificationDetails(
        '...',
        '...',
        '...',
        actions: <AndroidNotificationAction>[
          AndroidNotificationAction('id_1', 'Action 1'),
          AndroidNotificationAction('id_2', 'Action 2'),
          AndroidNotificationAction('id_3', 'Action 3'),
        ],
      );
      const NotificationDetails notificationDetails =
          NotificationDetails(android: androidNotificationDetails);
      await flutterLocalNotificationsPlugin.show(
          0, '...', '...', notificationDetails);
    }
    

    ios

    final DarwinInitializationSettings initializationSettingsDarwin = DarwinInitializationSettings(
        // ...
        notificationCategories: [
        const DarwinNotificationCategory(
            'demoCategory',
            <DarwinNotificationAction>[
                DarwinNotificationAction('id_1', 'Action 1'),
                DarwinNotificationAction(
                'id_2',
                'Action 2',
                options: <DarwinNotificationActionOption>{
                    DarwinNotificationActionOption.destructive,
                },
                ),
                DarwinNotificationAction(
                'id_3',
                'Action 3',
                options: <DarwinNotificationActionOption>{
                    DarwinNotificationActionOption.foreground,
                },
                ),
            ],
            options: <DarwinNotificationCategoryOption>{
                DarwinNotificationCategoryOption.hiddenPreviewShowTitle,
            },
        )
    ],
    

    On iOS notification actions need to be configured before the app is started using the initialize method

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