CharacterCollectionGrid constructor

CharacterCollectionGrid({
  1. Key? key,
  2. required List<CharacterCollectionItem> characters,
  3. required ValueChanged<String> onCharacterTap,
  4. ValueChanged<String>? onSelect,
  5. String title = 'Character Collection',
  6. String emptyMessage = 'No characters available.',
  7. CharacterCollectionFilter filter = CharacterCollectionFilter.all,
  8. ValueChanged<CharacterCollectionFilter>? onFilterChanged,
  9. double maxGridHeight = 420,
})

Implementation

CharacterCollectionGrid({
  super.key,
  required this.characters,
  required this.onCharacterTap,
  this.onSelect,
  this.title = 'Character Collection',
  this.emptyMessage = 'No characters available.',
  this.filter = CharacterCollectionFilter.all,
  this.onFilterChanged,
  this.maxGridHeight = 420,
}) {
  if (title.trim().isEmpty || emptyMessage.trim().isEmpty) {
    throw ArgumentError('title and emptyMessage must not be empty');
  }
  if (!maxGridHeight.isFinite || maxGridHeight <= 0) {
    throw ArgumentError.value(
      maxGridHeight,
      'maxGridHeight',
      'must be positive and finite',
    );
  }
  final ids = <String>{};
  for (final character in characters) {
    if (character.id.trim().isEmpty || character.name.trim().isEmpty) {
      throw ArgumentError.value(
        character,
        'characters',
        'id and name must not be empty',
      );
    }
    if (!ids.add(character.id)) {
      throw ArgumentError.value(
        character.id,
        'characters',
        'duplicate character id',
      );
    }
    if (character.isSelected && !character.isOwned) {
      throw ArgumentError.value(
        character.id,
        'characters',
        'locked character cannot be selected',
      );
    }
  }
  if (characters.where((c) => c.isSelected).length > 1) {
    throw ArgumentError.value(
      characters,
      'characters',
      'at most one character may be selected',
    );
  }
}