DonationOffer.fromNews constructor

DonationOffer.fromNews(
  1. AppNewsItem? item
)

Falls back field by field, so a feed carrying none of this renders the screen exactly as it shipped.

Implementation

factory DonationOffer.fromNews(AppNewsItem? item) {
  final String? currency = item?.currency;
  final List<int> amounts = _ladder(item?.donationAmounts);
  final num? scansPerUnit = item?.donationScansPerUnit;
  final num? reminderEvery = item?.donationReminderEvery;
  final num? donorCount = item?.count;
  final num? newArmPercent = item?.donationAbNewPercent;
  final num? stripHideDays = item?.donationStripHideDays;

  return DonationOffer(
    currency: currency != null && currency.length == 3
        ? currency
        : _fallbackCurrency,
    amounts: amounts.isEmpty ? _fallbackAmounts : amounts,
    scansPerUnit: scansPerUnit != null && _isUsable(scansPerUnit)
        ? scansPerUnit.toInt()
        : _fallbackScansPerUnit,
    whereItGoes: item?.donationWhereItGoes ?? const <String>[],
    reminderEvery: reminderEvery != null && _isUsableCount(reminderEvery)
        ? reminderEvery.toInt()
        : _fallbackReminderEvery,
    newArmPercent: newArmPercent != null && newArmPercent.isFinite
        ? newArmPercent.toInt()
        : 0,
    stripHideDays:
        stripHideDays != null &&
            _isUsableCount(stripHideDays) &&
            stripHideDays <= 365
        ? stripHideDays.toInt()
        : _fallbackStripHideDays,
    donorCount: donorCount != null && _isUsableCount(donorCount)
        ? donorCount.toInt()
        : null,
    funding: item?.funding,
    monthsLeft: item?.monthsLeft,
  );
}