aves_mio1/lib/utils/file_utils.dart
FabioMich66 19a982ede6
Some checks are pending
Quality check / Flutter analysis (push) Waiting to run
Quality check / CodeQL analysis (java-kotlin) (push) Waiting to run
first commit
2026-03-05 15:51:30 +01:00

16 lines
600 B
Dart

import 'package:intl/intl.dart';
const kilo = 1024;
const mega = kilo * kilo;
const giga = mega * kilo;
const tera = giga * kilo;
String formatFileSize(String locale, int size, {int round = 2}) {
if (size < kilo) return '$size B';
final compactFormatter = NumberFormat('0${round > 0 ? '.${'0' * round}' : ''}', locale);
if (size < mega) return '${compactFormatter.format(size / kilo)} KB';
if (size < giga) return '${compactFormatter.format(size / mega)} MB';
if (size < tera) return '${compactFormatter.format(size / giga)} GB';
return '${compactFormatter.format(size / tera)} TB';
}