Refactor profile tile
This commit is contained in:
@@ -4,6 +4,17 @@ import 'package:intl/intl.dart';
|
||||
|
||||
const _units = ["B", "kB", "MB", "GB", "TB"];
|
||||
|
||||
({String size, String unit}) formatByte(int input, {int? unit}) {
|
||||
const base = 1024;
|
||||
if (input <= 0) return (size: "0", unit: _units[unit ?? 0]);
|
||||
final int digitGroups = unit ?? (log(input) / log(base)).round();
|
||||
return (
|
||||
size: NumberFormat("#,##0.#").format(input / pow(base, digitGroups)),
|
||||
unit: _units[digitGroups],
|
||||
);
|
||||
}
|
||||
|
||||
// TODO remove
|
||||
({String size, String unit}) formatByteSpeed(int speed) {
|
||||
const base = 1024;
|
||||
if (speed <= 0) return (size: "0", unit: "B/s");
|
||||
@@ -13,10 +24,3 @@ const _units = ["B", "kB", "MB", "GB", "TB"];
|
||||
unit: "${_units[digitGroups]}/s",
|
||||
);
|
||||
}
|
||||
|
||||
String formatTrafficByteSize(int consumption, int total) {
|
||||
const base = 1024;
|
||||
if (total <= 0) return "0 B / 0 B";
|
||||
final formatter = NumberFormat("#,##0.#");
|
||||
return "${formatter.format(consumption / pow(base, 3))} GB / ${formatter.format(total / pow(base, 3))} GB";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user