fix(ads): banner retries load when SDK becomes ready

On a cold start the consent flow is still running when home first builds, so
createBanner returns null and the slot stayed empty until a rebuild. AdService
now exposes an isReady ValueNotifier; BannerAdSlot listens and retries its load
once MobileAds finishes initializing. Verified: analyze clean, 169 tests green.
This commit is contained in:
2026-06-13 14:23:45 +09:00
parent 70f87ab8f2
commit 640b23804f
2 changed files with 28 additions and 4 deletions
+10 -1
View File
@@ -1,6 +1,7 @@
// lib/services/ad_service.dart
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
import 'ad_config.dart';
@@ -29,11 +30,18 @@ class AdService {
RewardedAd? _rewarded;
bool _initialized = false;
/// Called by ConsentService once the SDK is initialized. Preloads ads.
/// Flips true once the SDK is initialized. Banner slots that were built
/// before consent finished listen to this and retry their load — otherwise
/// the banner would stay empty until the screen is rebuilt.
final ValueNotifier<bool> isReady = ValueNotifier<bool>(false);
/// Called by ConsentService once the SDK is initialized. Preloads ads and
/// notifies any waiting banner slots.
void onSdkReady() {
_initialized = true;
_loadInterstitial();
_loadRewarded();
isReady.value = true;
}
// ---- lifecycle hooks the game calls ----
@@ -137,5 +145,6 @@ class AdService {
void dispose() {
_interstitial?.dispose();
_rewarded?.dispose();
isReady.dispose();
}
}