Skip to content

Commit b748c85

Browse files
committed
refactor(settings): inject InlineAdCacheService for better testability
- Inject InlineAdCacheService into SettingsBloc constructor - Replace direct calls to InlineAdCacheService with injected instance - Improve code testability by using dependency injection
1 parent d5c85cf commit b748c85

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/settings/bloc/settings_bloc.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
2020
/// {@macro settings_bloc}
2121
SettingsBloc({
2222
required DataRepository<UserAppSettings> userAppSettingsRepository,
23+
required InlineAdCacheService inlineAdCacheService,
2324
}) : _userAppSettingsRepository = userAppSettingsRepository,
25+
_inlineAdCacheService = inlineAdCacheService,
2426
super(const SettingsState()) {
2527
// Register event handlers
2628
on<SettingsLoadRequested>(_onLoadRequested);
@@ -52,6 +54,7 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
5254
}
5355

5456
final DataRepository<UserAppSettings> _userAppSettingsRepository;
57+
final InlineAdCacheService _inlineAdCacheService;
5558

5659
Future<void> _persistSettings(
5760
UserAppSettings settingsToSave,
@@ -167,7 +170,7 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
167170
// When the theme's accent color changes, ads must be reloaded to reflect
168171
// the new styling. Clearing the cache ensures that any visible or
169172
// soon-to-be-visible ads are fetched again with the updated theme.
170-
InlineAdCacheService().clearAllAds();
173+
_inlineAdCacheService.clearAllAds();
171174
await _persistSettings(updatedSettings, emit);
172175
}
173176

@@ -232,7 +235,7 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
232235
// (small or medium) is requested. To ensure the correct ad format is
233236
// displayed, the cache must be cleared, forcing a new ad load with the
234237
// appropriate template.
235-
InlineAdCacheService().clearAllAds();
238+
_inlineAdCacheService.clearAllAds();
236239
await _persistSettings(updatedSettings, emit);
237240
}
238241

0 commit comments

Comments
 (0)