showNotification method

  1. @override
Future<bool> showNotification({
  1. required int id,
  2. String? title,
  3. String? body,
  4. required String channelId,
  5. required String channelName,
  6. String? payload,
  7. String? largeIcon,
  8. String? bigPicture,
  9. String? smallIcon,
  10. String? visibility,
  11. String? accentColor,
  12. List<Map<String, String?>>? buttons,
})
override

Post a notification from native code (used to render foreground pushes on Android, since FCM does not draw one while the app is open). Returns true if it was shown. No-op / false where unsupported. payload is stashed on the tap intent and delivered back via onNotificationTap.

Implementation

@override
Future<bool> showNotification({
  required int id,
  String? title,
  String? body,
  required String channelId,
  required String channelName,
  String? payload,
  String? largeIcon,
  String? bigPicture,
  String? smallIcon,
  String? visibility,
  String? accentColor,
  List<Map<String, String?>>? buttons,
}) async {
  try {
    final ok = await methodChannel.invokeMethod<bool>('showNotification', {
      'id': id,
      'title': title,
      'body': body,
      'channelId': channelId,
      'channelName': channelName,
      'payload': payload,
      'largeIcon': largeIcon,
      'bigPicture': bigPicture,
      'smallIcon': smallIcon,
      'visibility': visibility,
      'accentColor': accentColor,
      'buttons': buttons,
    });
    return ok ?? false;
  } catch (_) {
    return false;
  }
}