import 'package:hooks_riverpod/hooks_riverpod.dart'; import '../../mall/application/mall_tab_config.dart'; import '../data/ads_api_client.dart'; import 'splash_ad_controller.dart'; final adConfigForegroundRefresherProvider = Provider( (ref) => AdConfigForegroundRefresher( () => ref.invalidate(featuredAdsProvider(homeBannerAdPlacement)), () => ref.read(splashAdControllerProvider).refresh(), () => ref.read(mallTabConfigProvider.notifier).refresh(), ), ); class AdConfigForegroundRefresher { AdConfigForegroundRefresher(this._banner, this._splash, this._mall); final void Function() _banner; final Future Function() _splash, _mall; Future? _running; Future refresh({bool refreshMallTabConfig = true}) => _running ??= _refresh( refreshMallTabConfig: refreshMallTabConfig, ).whenComplete(() => _running = null); Future _refresh({required bool refreshMallTabConfig}) async { try { _banner(); } catch (_) {} try { await _splash(); } catch (_) {} if (refreshMallTabConfig) { try { await _mall(); } catch (_) {} } } }