checkForNotifications function

void checkForNotifications()

Implementation

void checkForNotifications() async {
  final prefs = await SharedPreferences.getInstance();

  final flutterDeviceId = prefs.getInt('flutterDeviceId');
  final flutterAppId = prefs.getInt('flutterAppId');
  final flutterAppToken = prefs.getString('flutterAppToken');

  try {
    var response = await http.read(Uri.parse(
        '$host/api/flutter/notification/$flutterDeviceId/$flutterAppId/$flutterAppToken'));

    List<dynamic> notifications = jsonDecode(response);

    for (var i = 0; i < notifications.length; i++) {
      var dataObject =
          await jsonDecode(notifications[i]['notification_data_object']);
      pushDataObject = dataObject;

      if (notifications[i]['notification_big_picture_url'] == null ||
          notifications[i]['notification_big_picture_url'] == '') {
        AwesomeNotifications().createNotification(
          content: NotificationContent(
              id: notifications[i]['flutter_notification_id'],
              channelKey: 'mass',
              title: notifications[i]['notification_title'],
              body: notifications[i]['notification_body']),
        );
      } else {
        AwesomeNotifications().createNotification(
          content: NotificationContent(
              id: notifications[i]['flutter_notification_id'],
              channelKey: 'mass',
              title: notifications[i]['notification_title'],
              body: notifications[i]['notification_body'],
              bigPicture: notifications[i]['notification_big_picture_url'],
              notificationLayout: NotificationLayout.BigPicture),
        );
      }
    }
  } catch (e) {
    // print(e);
  }
}