showNotification2 static method

Future<void> showNotification2({
  1. required dynamic message,
  2. required FlutterLocalNotificationsPlugin fln,
  3. bool data = false,
})

Implementation

static Future<void> showNotification2( { required /*RemoteMessage*/ message, required FlutterLocalNotificationsPlugin fln, bool data=false}) async {
  String? title;
  String? body;
  String? orderID;
  String? image;
  if(data) {
    var info = MessageNotification.fromJson(message.data);
    title = info.title;//message.data['title'];
    body = info.body;//message.data['body'];
    orderID = info.title;//message.data['order_id'];
    image = info.image;
    // image = (message.data['image'] != null && message.data['image'].isNotEmpty)
    //     ? message.data['image'].startsWith('http') ? message.data['image']
    //     : '${ApiConstant.urlWebServer}/storage/app/public/notification/${message.data['image']}' : null;
  }else {
    title = message.notification?.title;
    body = message.notification?.body;
    orderID = message.notification?.titleLocKey;
    if(GetPlatform.isAndroid) {
      String imageUrl = TypeSafeConversion.nullSafeString( message.notification?.android?.imageUrl );
      image = (imageUrl.isNotEmpty)
          ? imageUrl.startsWith('http') ? imageUrl
          : '${ApiConstantDev.urlWebServer}/storage/app/public/notification/$imageUrl' : null;
    }else if(GetPlatform.isIOS) {
      String imageUrl = TypeSafeConversion.nullSafeString( message.notification?.apple?.imageUrl );
      image = (imageUrl.isNotEmpty)
          ? imageUrl.startsWith('http') ? imageUrl
          : '${ApiConstantDev.urlWebServer}/storage/app/public/notification/$imageUrl' : null;
    }
  }

  if(image != null && image.isNotEmpty) {
    try{
      await showBigPictureNotificationHiddenLargeIcon2(title??'', body??'', orderID??'', image, fln);
    }catch(e) {
      await showBigTextNotification2(title??'', body??'', orderID??'', fln);
    }
  }else {
    await showBigTextNotification2(title??'', body??'', orderID??'', fln);
  }
}