mirror of
https://github.com/immich-app/immich.git
synced 2024-12-17 12:22:31 +02:00
27488ceb67
* dep(mobile): update flutter and deps * chore: dart analyzer * chore: update flutter workflow version * chore: dart format * fix: gallery_viewer PopScope --------- Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
17 lines
396 B
Dart
17 lines
396 B
Dart
String formatBytes(int bytes) {
|
|
const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB'];
|
|
|
|
int magnitude = 0;
|
|
double remainder = bytes.toDouble();
|
|
while (remainder >= 1024) {
|
|
if (magnitude + 1 < units.length) {
|
|
magnitude++;
|
|
remainder /= 1024;
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
|
|
return "${remainder.toStringAsFixed(magnitude == 0 ? 0 : 1)} ${units[magnitude]}";
|
|
}
|