formatFileSize static method

String formatFileSize(
  1. int bytes
)

Implementation

static String formatFileSize(int bytes) {
  if (bytes <= 0) return "0 B";
  const suffixes = ["B", "KB", "MB", "GB", "TB"];
  var i = (log(bytes) / log(1024)).floor();
  i = i < suffixes.length ? i : suffixes.length - 1;
  return '${(bytes / pow(1024, i)).toStringAsFixed(1)} ${suffixes[i]}';
}