formatFileSize function
Formats a byte count to a human-readable string (KB, MB, GB).
Example: formatFileSize(1536) returns "1.5KB".
Implementation
String formatFileSize(int sizeInBytes) {
final kb = sizeInBytes / 1024;
if (kb < 1) return '$sizeInBytes bytes';
if (kb < 1024) {
return '${_trimTrailingZero(kb.toStringAsFixed(1))}KB';
}
final mb = kb / 1024;
if (mb < 1024) {
return '${_trimTrailingZero(mb.toStringAsFixed(1))}MB';
}
final gb = mb / 1024;
return '${_trimTrailingZero(gb.toStringAsFixed(1))}GB';
}