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