parseDuration static method

int? parseDuration(
  1. String? time
)

Implementation

static int? parseDuration(String? time) {
  if (time == null) return null;

  final parts = time.split(":").reversed.map(int.parse).toList();
  final seconds = parts[0];
  final minutes = parts[1];
  late final int hours;

  if (parts.length > 2) {
    hours = parts[2];
  } else {
    hours = 0;
  }

  return seconds + minutes * 60 + hours * 60 * 60;
}