1
0
Fork 0
forked from Nexus/nexus
nexus/lib/helpers/extensions/size_to_string.dart
Henry-Hiles 16cf126df4 Remove flutter chat (#26)
Had to squash merge manually as Forgejo was erroring
2026-05-21 17:02:08 -04:00

22 lines
465 B
Dart

import "package:fast_immutable_collections/fast_immutable_collections.dart";
extension SizeToString on int {
String get sizeAsString {
const IListConst<String> suffixes = IListConst([
"B",
"KB",
"MB",
"GB",
"TB",
"PB",
]);
var i = 0;
var size = toDouble();
while (size > 1024 && i < suffixes.length - 1) {
size /= 1024;
i++;
}
return "${size.toStringAsFixed(2)} ${suffixes[i]}";
}
}