Search code examples
androidflutternotificationsflutter-local-notification

flutter_local_notifications: notifications are not shown in the foreground in Android


I am using flutter_local_notifications package in a Flutter App, I have initialized the package and configured everything, but the notifications are not shown in the foreground (Floating Notifications) ...

I'm testing with Xiaomi POCO X3 Pro with Android 12 and MIUI 13.0.5 ...

Any Ideas please?


Solution

  • After a lot of trials, what has worked for me is to set the importance to Importance.max in the AndroidNotificationDetails in the NotificationDetails passed to show() method like thee following:

    const _notificationDetails = NotificationDetails(
      android: AndroidNotificationDetails(
        'your_channel_id',
        'your_channel_name',
        importance: Importance.max,
      ),
    );
    
    await FlutterLocalNotificationsPlugin().show(
      0,
      'Notification Title',
      'Notification Body',
      _notificationDetails, // Here you should pass the `NotificationDetails` object
      payload: 'item x',
    );