formatFileSize static method
Format file size in human-readable format
Example:
FSUtils.formatFileSize(1024); // '1.0 KB'
FSUtils.formatFileSize(1048576); // '1.0 MB'
Implementation
static String formatFileSize(int bytes) {
assert(bytes >= 0, 'Bytes cannot be negative');
if (bytes < 1024) return '$bytes B';
if (bytes < 1048576) return '${(bytes / 1024).toStringAsFixed(1)} KB';
if (bytes < 1073741824) return '${(bytes / 1048576).toStringAsFixed(1)} MB';
return '${(bytes / 1073741824).toStringAsFixed(1)} GB';
}