1

If I use the show() method of the FlutterLocalNotificationsPlugin then I get a notification on Android but not on ios.

showNotification(
    String notificationId, String title, String body, String payload) async {
  final AndroidNotificationDetails androidPlatformChannelSpecifics =
      AndroidNotificationDetails(
          "important-notifications",
          tr("DEVICE.IMPORTANT_NOTIFICATIONS_NAME"),
          tr("DEVICE.IMPORTANT_NOTIFICATIONS_DESCRIPTION"),
          importance: Importance.max,
          priority: Priority.high,
          ledColor: Colors.pink,
          ledOffMs: 50,
          ledOnMs: 50,
          color: Colors.purple,
          styleInformation: BigTextStyleInformation(""),
          ticker: 'ticker');

  final NotificationDetails platformChannelSpecifics = NotificationDetails(
    android: androidPlatformChannelSpecifics,
  );
  await flutterLocalNotificationsPlugin
      .show(0, title, body, platformChannelSpecifics, payload: payload);
}

The solution to this problem is below.

1 Answer 1

3

There's a problem with platform specifics in the flutter_local_notifications plugin.

For example, if you use

await flutterLocalNotificationsPlugin
          .resolvePlatformSpecificImplementation<
              AndroidFlutterLocalNotificationsPlugin>()
          .createNotificationChannel(channel);

inside of your local notification initialization function, then the function will stop at this point if you're not on an android device. This results in not initializing the plugin with ios + android settings.

Solution To fix this just wrap everything you do with .resolvePlatformSpecificImplementation into a platform check

if (Platform.isAndroid) {
      await flutterLocalNotificationsPlugin
          .resolvePlatformSpecificImplementation<
              AndroidFlutterLocalNotificationsPlugin>()
          .createNotificationChannel(channel);
    }
if (Platform.isIOS) {
      await flutterLocalNotificationsPlugin
          .resolvePlatformSpecificImplementation<
              IOSFlutterLocalNotificationsPlugin>()
          .requestPermissions(
            alert: true,
            badge: true,
            sound: true,
          );
    } 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.