parseHumanReadableFilesize method Null safety

num parseHumanReadableFilesize(
  1. String input
)

Converts a human readable filesize string (either in metric or in binary units) to an integer number of bytes

Implementation

static num parseHumanReadableFilesize(String input) {
  num size = 0;

  //converts xiB or xB to bytes
  for (var base in basesString.entries.toList().reversed) {
    for (var unit in units.reversed) {
      if (input.contains("$unit${basesString[base.key]}")) {
        num value = num.parse(
            input.replaceAll("$unit${basesString[base.key]}", "").trim());
        size = (value *
            (Math.pow(basesValue[base.key] ?? 1024, units.indexOf(unit))));

        return size;
      }
    }
  }

  return size;
}