loadPushNotifications method

Future<List<PamPushMessage>?> loadPushNotifications()

Implementation

Future<List<PamPushMessage>?> loadPushNotifications() async {
  Response? response;
  var db = await Pam.shared.getDatabaseAlias();
  var contact = await Pam.shared.getContactID();
  Pam.log(["LOAD PUSH NOTIFICATION", "_database=$db&_contact_id=$contact"]);
  try {
    var uri = Uri.parse(
        "$baseURL/api/app-notifications?_database=$db&_contact_id=$contact");
    response = await HttpClient.get(uri);
    Pam.log([
      "LOAD PUSH NOTIFICATION",
      uri,
      "contact id = $contact",
      "πŸš₯πŸš₯πŸš₯πŸš₯πŸš₯ RESULT πŸš₯πŸš₯πŸš₯πŸš₯πŸš₯",
      "Status Code: ${response.statusCode}",
      "----- Response Body -----",
      response.body,
    ]);
  } catch (e, stackTrace) {
    Pam.log(["ERROR", stackTrace, e]);
  }

  if (response != null) {
    return PamPushMessage.parse(response.body);
  }

  return null;
}