getTasksWithStatus method

  1. @override
Future<List<BackgroundTaskInfo>> getTasksWithStatus({
  1. required List<BtmTaskStatus> status,
})
override

Implementation

@override
Future<List<BackgroundTaskInfo>> getTasksWithStatus({required List<BtmTaskStatus> status}) async {
  try {
    debugPrint("getTasksWithStatus start $status");
    if (!_startedInitialization) {
      throw Exception("BackgroundTaskManager initialization not initiated. Please call BackgroundTaskManager.singleton.init()");
    }
    if (!initCompletable.isCompleted) await initCompletable.future;
    if (!isInitialized) throw Exception("BackgroundTaskManager is not initialized.");
    final workInfos = await _methodChannel.invokeMethod<List>("getTasksByStatus", {"status": status.map((e) => e.name).toList()});
    debugPrint("getTasksWithStatus got $workInfos of type : ${workInfos.runtimeType}");
    final idList = <String>[];
    workInfos?.forEach((element) {
      debugPrint("getTasksWithStatus $element type : ${element.runtimeType}");
      if (element is Map) idList.add(element["taskId"]);
    });
    debugPrint("getTasksWithStatus idList : $idList");
    return await cache.getTasks(idList);
  } on Exception catch (e) {
    debugPrint("BackgroundTaskManager getTasksWithStatus exception $e");
    rethrow;
  }
}