formatDelta static method
String
formatDelta(
- SizeDelta delta, {
- NegativeValueOptions options = NegativeValueOptions.defaults,
- int decimals = 2,
Format a byte delta with direction awareness.
Implementation
static String formatDelta(
SizeDelta delta, {
NegativeValueOptions options = NegativeValueOptions.defaults,
int decimals = 2,
}) {
if (delta.isUnchanged) {
return options.unchangedLabel;
}
final converter = ByteConverter(delta.absoluteDifference);
final baseStr = converter.display.auto(precision: decimals);
if (options.mode == NegativeDisplayMode.custom &&
options.customFormatter != null) {
return options.customFormatter!(delta.difference, delta.isDecrease);
}
if (delta.isIncrease) {
return '${options.increasePrefix}$baseStr${options.increaseSuffix}';
}
switch (options.mode) {
case NegativeDisplayMode.minusSign:
return '${options.decreasePrefix}$baseStr${options.decreaseSuffix}';
case NegativeDisplayMode.parentheses:
return '($baseStr)';
case NegativeDisplayMode.decreaseSuffix:
return '$baseStr decrease';
case NegativeDisplayMode.reductionSuffix:
return '$baseStr reduction';
case NegativeDisplayMode.lossSuffix:
return '$baseStr loss';
case NegativeDisplayMode.absolute:
return baseStr;
case NegativeDisplayMode.custom:
return baseStr;
}
}