uFormatBytes function
Implementation
String uFormatBytes(int bytes) {
if (bytes < 0) return "—";
const List<String> units = <String>["B", "KB", "MB", "GB", "TB"];
double value = bytes.toDouble();
int unit = 0;
while (value >= 1024 && unit < units.length - 1) {
value /= 1024;
unit++;
}
return "${value.toStringAsFixed(unit == 0 ? 0 : 1)} ${units[unit]}";
}