Now this feature is stable, we should use it. I might have missed some usecases, but these can be added in future commits.
15 lines
403 B
Dart
15 lines
403 B
Dart
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
|
|
|
extension SizeToString on int {
|
|
String get sizeAsString {
|
|
const 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]}";
|
|
}
|
|
}
|