fix scroll controller errors

This commit is contained in:
Tommy Chow 2025-08-23 00:13:50 -07:00
parent 856f8aebd2
commit 25acfe9047
2 changed files with 36 additions and 17 deletions

View file

@ -42,15 +42,8 @@ class StreamsList extends StatefulWidget {
class _StreamsListState extends State<StreamsList>
with AutomaticKeepAliveClientMixin, WidgetsBindingObserver {
late final _listStore = ListStore(
authStore: context.read<AuthStore>(),
settingsStore: context.read<SettingsStore>(),
twitchApi: context.read<TwitchApi>(),
listType: widget.listType,
categoryId: widget.categoryId,
scrollController: widget.scrollController ??
(widget.showJumpButton ? ScrollController() : null),
);
late final ListStore _listStore;
ScrollController? _scrollController;
@override
bool get wantKeepAlive => true;
@ -59,6 +52,26 @@ class _StreamsListState extends State<StreamsList>
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
if (widget.scrollController == null && widget.showJumpButton) {
_scrollController = ScrollController();
}
_listStore = ListStore(
authStore: context.read<AuthStore>(),
settingsStore: context.read<SettingsStore>(),
twitchApi: context.read<TwitchApi>(),
listType: widget.listType,
categoryId: widget.categoryId,
scrollController: widget.scrollController ?? _scrollController,
);
}
@override
void dispose() {
_scrollController?.dispose();
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
@ -288,11 +301,4 @@ class _StreamsListState extends State<StreamsList>
),
);
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
_listStore.dispose();
super.dispose();
}
}

View file

@ -19,6 +19,17 @@ class _AnimatedScrollBorderState extends State<AnimatedScrollBorder> {
void initState() {
super.initState();
widget.scrollController.addListener(_updateScrollState);
_updateScrollState(); // Initial check
}
@override
void didUpdateWidget(AnimatedScrollBorder oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.scrollController != oldWidget.scrollController) {
oldWidget.scrollController.removeListener(_updateScrollState);
widget.scrollController.addListener(_updateScrollState);
_updateScrollState(); // Initial check for new controller
}
}
@override
@ -28,8 +39,10 @@ class _AnimatedScrollBorderState extends State<AnimatedScrollBorder> {
}
void _updateScrollState() {
if (!mounted) return;
setState(() {
_isScrolled = widget.scrollController.offset > 0;
_isScrolled = widget.scrollController.hasClients &&
widget.scrollController.offset > 0;
});
}