itemCount property
set
itemCount
(int value)
Updates the total item count (e.g., when list changes).
Automatically clamps focus to valid range and adjusts error list size.
Implementation
set itemCount(int value) {
final newCount = max(0, value);
if (newCount == _itemCount) return;
if (newCount > _itemCount) {
// Grow: add null errors for new items
_errors.addAll(List<String?>.filled(newCount - _itemCount, null));
} else {
// Shrink: remove trailing errors
_errors.removeRange(newCount, _itemCount);
}
_itemCount = newCount;
if (_itemCount == 0) {
_focusedIndex = 0;
} else {
_focusedIndex = _focusedIndex.clamp(0, _itemCount - 1);
}
}