retrieveRequests method

Future<List<EventRequest>> retrieveRequests()

Implementation

Future<List<EventRequest>> retrieveRequests() async {
  return await _lock.synchronized(() async {
    Debug.print("RequestCacher: Initializing stored requests retrieval");
    final globalProperties =
        await PerceptFlutterPlatform.instance.getGlobalProperties();
    final String jsonString = globalProperties?[cachedEventsKey] ?? "";
    if (jsonString.trim().isNotEmpty) {
      await _removeQueue();
      final List<dynamic> jsonList = jsonDecode(jsonString);
      final eventRequests =
          jsonList.map((e) => EventRequest.fromJson(jsonDecode(e))).toList();
      Debug.print("RequestCacher:Retrieved ${eventRequests.length} requests");
      return eventRequests;
    } else {
      Debug.print("RequestCacher: No pending requests");
      return [];
    }
  });
}