formatBytes static method

String formatBytes(
  1. int bytes,
  2. int decimals
)

Implementation

static String formatBytes(int bytes, int decimals) {
  if (bytes <= 0) return "0 B";
  const suffixes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
  var i = (log(bytes) / log(1024)).floor();
  return ((bytes / pow(1024, i)).toStringAsFixed(decimals)) +
      ' ' +
      suffixes[i];
}