Skip to content

Commit a4d2a22

Browse files
committed
feat(ads): enhance ad height determination logic
- Add support for different ad heights based on headlineImageStyle when bannerAdShape is null - Implement fallback mechanism for feed context using headlineImageStyle - Maintain existing logic for in-article context using bannerAdShape
1 parent cc45256 commit a4d2a22

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

lib/ads/widgets/demo_banner_ad_widget.dart

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,20 @@ class DemoBannerAdWidget extends StatelessWidget {
2727
Widget build(BuildContext context) {
2828
final theme = Theme.of(context);
2929

30-
// Determine the height based on the bannerAdShape if provided.
31-
// If bannerAdShape is square, use height for mediumRectangle (250).
32-
// Otherwise, use height for standard banner (50).
33-
final adHeight = switch (bannerAdShape) {
34-
BannerAdShape.square => 250,
35-
BannerAdShape.rectangle => 50,
36-
_ => 50, // Default to standard banner height if shape is null or unknown
37-
};
30+
// Determine the height. Prioritize bannerAdShape for in-article context.
31+
// Fall back to headlineImageStyle for feed context.
32+
final int adHeight;
33+
if (bannerAdShape != null) {
34+
adHeight = switch (bannerAdShape) {
35+
BannerAdShape.square => 250,
36+
BannerAdShape.rectangle => 50,
37+
_ => 50,
38+
};
39+
} else {
40+
adHeight = headlineImageStyle == HeadlineImageStyle.largeThumbnail
41+
? 250 // Height for mediumRectangle banner
42+
: 50; // Height for standard banner
43+
}
3844

3945
return Card(
4046
margin: const EdgeInsets.symmetric(

0 commit comments

Comments
 (0)