Skip to content

Commit 3b2326c

Browse files
committed
fix(ads): improve banner ad height logic in AdmobInlineAdWidget
- Add support for feed ads by considering headlineImageStyle - Prioritize bannerAdShape for in-article ads when both are provided - Adjust adHeight based on bannerAdShape or headlineImageStyle - Improve code readability and handling of different ad types
1 parent a4d2a22 commit 3b2326c

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

lib/ads/widgets/admob_inline_ad_widget.dart

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,20 @@ class _AdmobInlineAdWidgetState extends State<AdmobInlineAdWidget> {
112112
NativeAdTemplateType.medium => 340,
113113
};
114114
} else if (widget.inlineAd is BannerAd) {
115-
// For banner ads, adjust height based on bannerAdShape if provided.
116-
// If bannerAdShape is square, use height for mediumRectangle (250).
117-
// Otherwise, use height for standard banner (50).
118-
adHeight = switch (widget.bannerAdShape) {
119-
BannerAdShape.square => 250,
120-
BannerAdShape.rectangle => 50,
121-
_ =>
122-
50, // Default to standard banner height if shape is null or unknown
123-
};
115+
// For banner ads, prioritize bannerAdShape if provided (for in-article ads).
116+
// Otherwise, fall back to headlineImageStyle (for feed ads).
117+
if (widget.bannerAdShape != null) {
118+
adHeight = switch (widget.bannerAdShape) {
119+
BannerAdShape.square => 250,
120+
BannerAdShape.rectangle => 50,
121+
_ => 50,
122+
};
123+
} else {
124+
adHeight =
125+
widget.headlineImageStyle == HeadlineImageStyle.largeThumbnail
126+
? 250 // Assumes large thumbnail feed style wants a medium rectangle banner
127+
: 50;
128+
}
124129
} else {
125130
// Fallback height for unknown inline ad types.
126131
adHeight = 100;

0 commit comments

Comments
 (0)