aves_mio/lib/utils/file_utils.dart
Fabio Micheluz 2c988f959b
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-02-19 13:25:23 +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';
}