getFileSizeString static method

String getFileSizeString({
  1. required int bytes,
  2. int decimals = 0,
})

Implementation

static String getFileSizeString({required int bytes, int decimals = 0}) {
  const suffixes = ["b", "kb", "mb", "gb", "tb"];
  var i = (log(bytes) / log(1024)).floor();
  return ((bytes / pow(1024, i)).toStringAsFixed(decimals)) + suffixes[i];
}