feat: appbar
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import 'dart:math';
|
||||
|
||||
extension NumberToSizeExtension on num {
|
||||
String formatAsSize({int noOfDecimals = 0}) {
|
||||
const List<String> units = [
|
||||
'B',
|
||||
'KB',
|
||||
'MB',
|
||||
'GB',
|
||||
'TB',
|
||||
'PB',
|
||||
'EB',
|
||||
'ZB',
|
||||
'YB',
|
||||
];
|
||||
if (this == 0) return '0 B';
|
||||
final index = (log(this) / log(1024)).floor();
|
||||
final byteIndex = index.clamp(0, units.length - 1);
|
||||
|
||||
final size = (this / pow(1024, byteIndex)).round();
|
||||
// ignore: avoid-unsafe-collection-methods
|
||||
return '${size.toStringAsFixed(noOfDecimals)} ${units[byteIndex]}';
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
extension StringNumberUtils on String {
|
||||
int? tryParseInt() => int.tryParse(this);
|
||||
int parseInt() => int.parse(this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user