progressWhere method

double progressWhere({
  1. String? category,
  2. bool? blocksUserInteraction,
})

Weighted progress across tasks matching category/blocking filters.

Implementation

double progressWhere({
  String? category,
  bool? blocksUserInteraction,
}) {
  var progress = 0.0;
  var weight = 0.0;
  for (final details in tasks.values) {
    if (!_matchesTaskFilter(
      details,
      category: category,
      blocksUserInteraction: blocksUserInteraction,
    )) {
      continue;
    }
    final value = switch (details.status) {
      LxSuccess() => 1.0,
      LxWaiting() => details.progress,
      _ => 0.0,
    };
    progress += value * details.weight;
    weight += details.weight;
  }
  return weight == 0 ? 0 : progress / weight;
}