Files
sharedinbox/lib/core/utils/format_utils.dart
T

10 lines
383 B
Dart
Raw Normal View History

/// Returns a human-readable file size string (B / KB / MB / GB).
String fmtSize(int bytes) {
if (bytes < 1024) return '$bytes B';
if (bytes < 1024 * 1024) return '${(bytes / 1024).toStringAsFixed(1)} KB';
if (bytes < 1024 * 1024 * 1024) {
return '${(bytes / (1024 * 1024)).toStringAsFixed(1)} MB';
}
return '${(bytes / (1024 * 1024 * 1024)).toStringAsFixed(1)} GB';
}