formatBytes static method
Implementation
static String formatBytes(int bytes, [int decimals = 2]) {
if (bytes <= 0) return "0 B";
const suffixes = ["bytes", "KB", "MB", "GB", "TB"];
int i = (bytes == 0) ? 0 : (log(bytes) / log(1024)).floor();
double size = bytes / (1 << (10 * i));
return "${NumberFormat('0.${''.padLeft(decimals, '#')}').format(size)} ${suffixes[i]}";
}