Skip to content

Commit 5adc718

Browse files
committed
void dispose() { // The ad object (_loadedAd) is intentionally not disposed of here. // Its lifecycle is managed by the InlineAdCacheService. The cache for this // feed's context (e.g., 'all', 'followed', or a filter ID) is cleared // by the HeadlinesFeedBloc during a pull-to-refresh, which is the // correct and only time these feed ads should be disposed. This prevents // ads from being destroyed when they scroll out of view. // Cancel any pending ad loading operation when the widget is disposed. // This prevents `setState()` calls on a disposed widget. if (_loadAdCompleter != null && !_loadAdCompleter!.isCompleted) {
1 parent b867d53 commit 5adc718

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/ads/widgets/feed_ad_loader_widget.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,13 @@ class _FeedAdLoaderWidgetState extends State<FeedAdLoaderWidget> {
141141

142142
@override
143143
void dispose() {
144-
// The ad is intentionally not disposed of here. The InlineAdCacheService
145-
// is responsible for managing the ad's lifecycle. The cache for this
146-
// context ('all', 'followed', etc.) will be cleared by the
147-
// HeadlinesFeedBloc during a pull-to-refresh, which is the correct
148-
// time to dispose of these ads.
144+
// The ad object (_loadedAd) is intentionally not disposed of here.
145+
// Its lifecycle is managed by the InlineAdCacheService. The cache for this
146+
// feed's context (e.g., 'all', 'followed', or a filter ID) is cleared
147+
// by the HeadlinesFeedBloc during a pull-to-refresh, which is the
148+
// correct and only time these feed ads should be disposed. This prevents
149+
// ads from being destroyed when they scroll out of view.
150+
149151
// Cancel any pending ad loading operation when the widget is disposed.
150152
// This prevents `setState()` calls on a disposed widget.
151153
if (_loadAdCompleter != null && !_loadAdCompleter!.isCompleted) {

0 commit comments

Comments
 (0)