DailyOfferStack constructor

DailyOfferStack({
  1. Key? key,
  2. required List<DailyOffer> offers,
  3. required ValueChanged<String> onOpen,
  4. String title = 'Daily Offers',
  5. String emptyMessage = 'No offers available right now.',
  6. String? semanticLabel,
})

Implementation

DailyOfferStack({
  super.key,
  required this.offers,
  required this.onOpen,
  this.title = 'Daily Offers',
  this.emptyMessage = 'No offers available right now.',
  this.semanticLabel,
}) {
  if (title.trim().isEmpty) {
    throw ArgumentError.value(title, 'title', 'must not be empty');
  }
  if (emptyMessage.trim().isEmpty) {
    throw ArgumentError.value(
      emptyMessage,
      'emptyMessage',
      'must not be empty',
    );
  }
  final ids = <String>{};
  for (final offer in offers) {
    if (offer.id.trim().isEmpty) {
      throw ArgumentError.value(offer.id, 'offer.id', 'must not be empty');
    }
    if (!ids.add(offer.id)) {
      throw ArgumentError.value(
        offer.id,
        'offers',
        'duplicate offer id: ${offer.id}',
      );
    }
    if (offer.title.trim().isEmpty) {
      throw ArgumentError.value(
        offer.title,
        'offer.title',
        'must not be empty',
      );
    }
    if (offer.priceLabel.trim().isEmpty) {
      throw ArgumentError.value(
        offer.priceLabel,
        'offer.priceLabel',
        'must not be empty',
      );
    }
  }
}