formatBytes method
Human-readable byte size (e.g. 1.50 MB).
Implementation
String formatBytes({int decimals = 2}) {
const suffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
var v = toDouble();
var i = 0;
while (v >= 1024 && i < suffixes.length - 1) {
v /= 1024;
i++;
}
return '${v.toStringAsFixed(decimals)} ${suffixes[i]}';
}