CollectionAlbumPanel constructor

CollectionAlbumPanel({
  1. Key? key,
  2. required String title,
  3. required List<CollectionAlbumItem> items,
  4. required ValueChanged<String> onItemTap,
  5. String? completionRewardLabel,
  6. VoidCallback? onViewReward,
  7. String emptyMessage = 'No collectibles in this album.',
})

Implementation

CollectionAlbumPanel({
  super.key,
  required this.title,
  required this.items,
  required this.onItemTap,
  this.completionRewardLabel,
  this.onViewReward,
  this.emptyMessage = 'No collectibles in this album.',
}) {
  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 item in items) {
    if (item.id.trim().isEmpty || item.name.trim().isEmpty) {
      throw ArgumentError.value(
        item,
        'items',
        'id and name must not be empty',
      );
    }
    if (!ids.add(item.id)) {
      throw ArgumentError.value(
        item.id,
        'items',
        'duplicate item id: ${item.id}',
      );
    }
    if (item.ownedCount < 0 || item.requiredCount <= 0) {
      throw ArgumentError.value(
        item,
        'items',
        'ownedCount must be non-negative and requiredCount positive',
      );
    }
  }
  if (completionRewardLabel != null &&
      completionRewardLabel!.trim().isEmpty) {
    throw ArgumentError.value(
      completionRewardLabel,
      'completionRewardLabel',
      'must not be empty when provided',
    );
  }
}