fix: guard ScrollController.position access in HorizontalScrollWithArrows
Prevents "Too many elements" StateError on Android TV when the controller temporarily has multiple positions during widget rebuilds.
This commit is contained in:
@@ -52,7 +52,15 @@ class _HorizontalScrollWithArrowsState extends State<HorizontalScrollWithArrows>
|
||||
}
|
||||
|
||||
void _updateScrollState() {
|
||||
if (!mounted) return;
|
||||
if (!mounted || _scrollController.positions.length != 1) {
|
||||
if (mounted && (_canScrollLeft || _canScrollRight)) {
|
||||
setState(() {
|
||||
_canScrollLeft = false;
|
||||
_canScrollRight = false;
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
final position = _scrollController.position;
|
||||
setState(() {
|
||||
@@ -62,6 +70,7 @@ class _HorizontalScrollWithArrowsState extends State<HorizontalScrollWithArrows>
|
||||
}
|
||||
|
||||
void _animateScroll(double direction) {
|
||||
if (_scrollController.positions.length != 1) return;
|
||||
final position = _scrollController.position;
|
||||
final delta = direction * position.viewportDimension * widget.scrollAmount;
|
||||
final targetScroll = (position.pixels + delta).clamp(0.0, position.maxScrollExtent);
|
||||
|
||||
Reference in New Issue
Block a user