Skip to content

Commit 0f612a1

Browse files
committed
refactor(feed): pass theme data to ad service for themed ads
- Add ThemeData parameter to ad injection methods in FeedDecoratorService - Pass theme to _adService.getAd() when requesting an ad - Update method signatures to include theme parameter
1 parent 37afefe commit 0f612a1

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/shared/services/feed_decorator_service.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:math';
22

33
import 'package:core/core.dart';
44
import 'package:data_repository/data_repository.dart';
5+
import 'package:flutter/material.dart';
56
import 'package:flutter_news_app_mobile_client_full_source_code/ads/ad_service.dart';
67
import 'package:flutter_news_app_mobile_client_full_source_code/router/routes.dart';
78
import 'package:uuid/uuid.dart';
@@ -109,6 +110,7 @@ class FeedDecoratorService {
109110
required List<String> followedTopicIds,
110111
required List<String> followedSourceIds,
111112
required HeadlineImageStyle imageStyle,
113+
required ThemeData theme,
112114
}) async {
113115
// The final list of items to be returned.
114116
final feedWithDecorators = <FeedItem>[...headlines];
@@ -172,6 +174,7 @@ class FeedDecoratorService {
172174
required User? user,
173175
required AdConfig adConfig,
174176
required HeadlineImageStyle imageStyle,
177+
required ThemeData theme,
175178
int processedContentItemCount = 0,
176179
}) async {
177180
return _injectAds(
@@ -180,6 +183,7 @@ class FeedDecoratorService {
180183
adConfig: adConfig,
181184
processedContentItemCount: processedContentItemCount,
182185
imageStyle: imageStyle,
186+
theme: theme,
183187
);
184188
}
185189

@@ -371,6 +375,7 @@ class FeedDecoratorService {
371375
required User? user,
372376
required AdConfig adConfig,
373377
required HeadlineImageStyle imageStyle,
378+
required ThemeData theme,
374379
int processedContentItemCount = 0,
375380
}) async {
376381
final userRole = user?.appRole ?? AppUserRole.guestUser;
@@ -423,7 +428,10 @@ class FeedDecoratorService {
423428
if (currentContentItemCount >= adPlacementInterval &&
424429
(currentContentItemCount - adPlacementInterval) % adFrequency == 0) {
425430
// Request an ad from the AdService.
426-
final adToInject = await _adService.getAd(imageStyle: imageStyle);
431+
final adToInject = await _adService.getAd(
432+
imageStyle: imageStyle,
433+
theme: theme,
434+
);
427435
if (adToInject != null) {
428436
result.add(adToInject);
429437
}

0 commit comments

Comments
 (0)