For the complete documentation index, see llms.txt. This page is also available as Markdown.

Push Inbox

Push Inbox Overview

NetmeraInbox allows you to access and manage previously sent push notifications in an inbox-style interface. You cannot instantiate NetmeraInbox directly; instead, you must obtain an instance through the SDK and use it to interact with push notifications.

Filtering Notifications

Create a NetmeraInboxFilter instance to specify which push notifications to fetch. You can filter by:

  • Status: Read, Unread, or Deleted.

  • Categories: Filter by specific categories.

  • Expired Notifications: Include or exclude expired notifications.

  • Page Size: Number of notifications to fetch per request.

Netmera Inbox Examples

String _currentStatus = Netmera.PUSH_OBJECT_STATUS_ALL.toString();
String _count = "0";
List<NetmeraPushInbox> _pushInboxList = List.empty(growable: true);

List<DropdownMenuItem<String>> getInboxList() {
  List<DropdownMenuItem<String>> items = List.empty(growable: true);
  items.add(DropdownMenuItem(value: Netmera.PUSH_OBJECT_STATUS_ALL.toString(), child: const Text("ALL")));
  items.add(DropdownMenuItem(value: Netmera.PUSH_OBJECT_STATUS_READ.toString(), child: const Text("READ")));
  items.add(DropdownMenuItem(value: Netmera.PUSH_OBJECT_STATUS_UNREAD.toString(), child: const Text("UNREAD")));
  items.add(DropdownMenuItem(value: Netmera.PUSH_OBJECT_STATUS_DELETED.toString(), child: const Text("DELETED")));
  return items;
}

onInboxStatusChanged(String status) {
  setState(() {
    _currentStatus = status;
  });
}

String getStatusText(int status) {
  switch (status) {
    case Netmera.PUSH_OBJECT_STATUS_ALL:
      return "ALL";
    case Netmera.PUSH_OBJECT_STATUS_READ:
      return "READ";
    case Netmera.PUSH_OBJECT_STATUS_UNREAD:
      return "UNREAD";
    case Netmera.PUSH_OBJECT_STATUS_DELETED:
      return "DELETED";
  }
  return "";
}

fillInboxList(list) {
  setState(() {
    _pushInboxList = list;
  });
}

// Click Functions
emptyAction() {}

getInboxFilter() {
  NetmeraInboxFilter inboxFilter = NetmeraInboxFilter();
  inboxFilter.setPageSize(2);
  inboxFilter.setStatus(int.parse(_currentStatus));
  inboxFilter.setIncludeExpiredObjects(true);
  inboxFilter.setCategories(null);
  return inboxFilter;
}

fetchInbox() async {
  Netmera.fetchInbox(getInboxFilter()).then((list) {
    fillInboxList(list);
  }).catchError((error) {
    debugPrint(error);
  });
}

fetchNextPage() async {
  Netmera.fetchNextPage().then((list) {
    fillInboxList(list);
  }).catchError((error) {
    debugPrint(error);
  });
}

countForStatus() async {
  Netmera.countForStatus(int.parse(_currentStatus)).then((val) {
    setState(() {
      if (val != -1) {
        _count = val.toString();
      }
    });
  });
}

// Use this method to trigger the action associated with a push message in the inbox
handlePushObject() async {
  if (_pushInboxList.isNotEmpty) {
    Netmera.handlePushObject(_pushInboxList[0].getPushId()!);
  }
}

handleInteractiveAction() async {
  if (_pushInboxList.isNotEmpty) {
    for (var element in _pushInboxList) {
      if (element.getInteractiveActions() != null && element.getInteractiveActions()!.isNotEmpty) {
        Netmera.handleInteractiveAction(element.getInteractiveActions()![0]);
        return;
      }
    }
  }
}

inboxUpdateStatus() {
  List<String> selectedPushList = List.empty(growable: true);
  if (_pushInboxList.length > 1) {
    selectedPushList.add(_pushInboxList[0].getPushId()!);
    selectedPushList.add(_pushInboxList[1].getPushId()!);
  }
  int status = Netmera.PUSH_OBJECT_STATUS_UNREAD;
  Netmera.inboxUpdateStatus(selectedPushList, status).then((netmeraError) {
    if (netmeraError != null) {
      debugPrint(netmeraError);
    }
  }).catchError((error) {
    debugPrint(error);
  });
}

updateAll() async {
  if (_pushInboxList.isNotEmpty) {
    var updateStatus = int.parse(_currentStatus);
    if (updateStatus == Netmera.PUSH_OBJECT_STATUS_ALL) {
      debugPrint("Please select different status than all!!");
      return;
    }

    Netmera.updateAll(updateStatus).then((netmeraError) {
      fetchInbox();
    }).catchError((error) {
      debugPrint(error);
    });
  }
}

inboxCountForStatus() async {
  NMInboxStatusCountFilter filter = NMInboxStatusCountFilter();
  filter.setStatus(int.parse(_currentStatus));
  filter.setIncludeExpired(true);
  Netmera.getInboxCountForStatus(filter).then((map) {
    String countStatusText = "ALL: " +
        map[Netmera.PUSH_OBJECT_STATUS_ALL.toString()].toString() +
        ", " +
        "READ: " +
        map[Netmera.PUSH_OBJECT_STATUS_READ.toString()].toString() +
        ", " +
        "UNREAD: " +
        map[Netmera.PUSH_OBJECT_STATUS_UNREAD.toString()].toString() +
        ", " +
        "DELETED: " +
        map[Netmera.PUSH_OBJECT_STATUS_DELETED.toString()].toString();
    setState(() {
      _count = countStatusText;
    });
  }).catchError((error) {
    debugPrint(error);
  });
}

Netmera Inbox Category Examples

Last updated

Was this helpful?