CharacterCollectionGrid constructor
CharacterCollectionGrid({
- Key? key,
- required List<
CharacterCollectionItem> characters, - required ValueChanged<
String> onCharacterTap, - ValueChanged<
String> ? onSelect, - String title = 'Character Collection',
- String emptyMessage = 'No characters available.',
- CharacterCollectionFilter filter = CharacterCollectionFilter.all,
- ValueChanged<
CharacterCollectionFilter> ? onFilterChanged, - 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',
);
}
}