readableFileSize method

String readableFileSize({
  1. bool base1024 = true,
})

Implementation

String readableFileSize({bool base1024 = true}) {
  final base = base1024 ? 1024 : 1000;
  if (this <= 0) return "0";
  final units = ["bytes", "KB", "MB", "GB", "TB"];
  int digitGroups = (log(this) / log(base)).round();
  return "${NumberFormat("#,##0.#").format(this / pow(base, digitGroups))} ${units[digitGroups]}";
}