filter method

List<MoodleTask> filter({
  1. String? query,
  2. int? courseId,
  3. Set<int>? courseIds,
  4. int? taskId,
  5. Set<int>? taskIds,
  6. Duration? deadlineDiff,
  7. Duration? minDeadlineDiff,
  8. Duration? maxDeadlineDiff,
  9. Set<MoodleTaskStatus> status = const {},
  10. Set<MoodleTaskType> type = const {},
  11. bool test(
    1. MoodleTask
    )?,
})

Filters all MoodleTasks based on the provided criteria.

Returns a list of tasks that match all the specified filters. If no filters are provided, all tasks are returned.

The available filters are:

  • query: A substring that must be present in the task's name (case-insensitive).
  • courseId: The course ID that the task must belong to.
  • deadlineDiff: The exact difference between the task's deadline and the current time.
  • minDeadlineDiff: The minimum allowed difference between the task's deadline and the current time.
  • maxDeadlineDiff: The maximum allowed difference between the task's deadline and the current time.
  • status: A set of acceptable task statuses. If provided, the task's status must be one of these.
  • type: A set of acceptable task types. If provided, the task's type must be one of these.

If state does not contain data, an empty list is returned.

Implementation

List<MoodleTask> filter({
  String? query,
  int? courseId,
  Set<int>? courseIds,
  int? taskId,
  Set<int>? taskIds,
  Duration? deadlineDiff,
  Duration? minDeadlineDiff,
  Duration? maxDeadlineDiff,
  Set<MoodleTaskStatus> status = const {},
  Set<MoodleTaskType> type = const {},
  bool Function(MoodleTask)? test,
}) {
  if (!state.hasData) return [];

  return state.requireData.filter(
    query: query,
    courseId: courseId,
    courseIds: courseIds,
    taskId: taskId,
    taskIds: taskIds,
    deadlineDiff: deadlineDiff,
    minDeadlineDiff: minDeadlineDiff,
    maxDeadlineDiff: maxDeadlineDiff,
    status: status,
    type: type,
    test: test,
  );
}