getNotifModel function

Notif? getNotifModel(
  1. RemoteMessage message
)

Implementation

Notif? getNotifModel(RemoteMessage message){
  try {
    var data = message.data;
    String? title = data['title'];
    String? content = data['content'];
    String? type = data['type'];
    String? image = type == "IMAGE" ? data['image'] : "";
    String? link = type == "LINK" ? data['link'] : "";

    Notif n = Notif(title, content);
    n.type = type;
    n.image = image;
    n.link = link;

    SQLiteDb dbHelper = SQLiteDb();
    final Future<Database> dbFuture = dbHelper.init();
    dbFuture.then((database) {
      dbHelper.insertNotification(n);
    });

    return n;

  } catch(error){
    return null;
  }
}