File: lib/screens/channel_detail_screen.dart
Line: ~79 (in build)
Description:
The ChannelDetailScreen calls _checkPollingNeeded(videos) inside its build() method via videosAsync.whenData().
Because videosAsync.whenData() directly invokes the callback with the resolved value during the build phase itself, this executes _pendingVideoIds.remove(id) and _startPolling()/_stopPolling() directly inside build(), which modifies widget state and starts timers outside the proper lifecycle hooks.
This is an anti-pattern and can cause race conditions or unhandled Flutter errors (setState() or markNeedsBuild() called during build).
Impact:
Unpredictable rebuild loops, UI lag, and hard-to-track polling bugs in the channel details view.
Suggested Fix:
Use ref.listen inside the build method rather than whenData, or execute the polling checks in a separate Riverpod Notifier completely decoupled from the widget layer.
ref.listen<AsyncValue<List<Video>>>(channelVideosProvider(widget.channelId), (prev, next) {
next.whenData((videos) => _checkPollingNeeded(videos));
});
File:
lib/screens/channel_detail_screen.dartLine: ~79 (in
build)Description:
The
ChannelDetailScreencalls_checkPollingNeeded(videos)inside itsbuild()method viavideosAsync.whenData().Because
videosAsync.whenData()directly invokes the callback with the resolved value during the build phase itself, this executes_pendingVideoIds.remove(id)and_startPolling()/_stopPolling()directly insidebuild(), which modifies widget state and starts timers outside the proper lifecycle hooks.This is an anti-pattern and can cause race conditions or unhandled Flutter errors (
setState() or markNeedsBuild() called during build).Impact:
Unpredictable rebuild loops, UI lag, and hard-to-track polling bugs in the channel details view.
Suggested Fix:
Use
ref.listeninside thebuildmethod rather thanwhenData, or execute the polling checks in a separate Riverpod Notifier completely decoupled from the widget layer.