stringify method
Implementation
PaywallLocalizedContent<String?> stringify({
bool? all,
required double? usdPrice,
required double? price,
required int unit,
required double discountPrice,
required String localizedPrice,
required String currencyCode,
}) {
if (isEmpty) return this;
final delegate = InAppPurchaser.i.configDelegate;
String formatPrice(double value, String currencyCode) {
if (delegate != null) {
final formatted = delegate.formatPrice(
InAppPurchaser.i.locale,
currencyCode,
value,
);
if (formatted != null) {
return delegate.formatZeros(formatted);
}
}
String str = value.toStringAsFixed(2);
str = str.replaceAll(RegExp(r'([.]*0+)$'), '');
return "$currencyCode $str";
}
double? formatNumber(double? b, double? r, double? c) {
if (b == null || r == null || c == null) return null;
final x = (r / b) * c;
if (delegate != null) return delegate.prettyPrice(x);
return (x.roundToDouble() + 0.99 - 1).abs();
}
return replaceAll(
all: all,
kDiscountPrice,
formatPrice(discountPrice, currencyCode),
)
.replaceAll(
all: all,
kFormatedPrice,
formatPrice(discountPrice / unit, currencyCode),
)
.replaceAll(
all: all,
kPrice,
formatPrice(
formatNumber(usdPrice, discountPrice, price) ?? discountPrice,
currencyCode,
),
)
.replaceAll(
all: all,
kLocalizedPrice,
localizedPrice,
);
}