Skip to content

Commit 4353bfb

Browse files
committed
feat(ads): enhance AdmobInlineAdWidget with banner ad shape configuration
- Add bannerAdShape parameter to AdmobInlineAdWidget for better banner ad customization - Implement logic to adjust banner ad height based on the specified shape - Update documentation to reflect new parameter and its usage
1 parent ee4b4ba commit 4353bfb

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/ads/widgets/admob_inline_ad_widget.dart

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,20 @@ class AdmobInlineAdWidget extends StatefulWidget {
2424
const AdmobInlineAdWidget({
2525
required this.inlineAd,
2626
this.headlineImageStyle,
27+
this.bannerAdShape,
2728
super.key,
2829
});
2930

3031
/// The generic inline ad model which contains the provider-specific AdMob ad object.
3132
final InlineAd inlineAd;
3233

3334
/// The user's preference for feed layout, used to determine the ad's visual size.
35+
/// This is only relevant for native ads.
3436
final HeadlineImageStyle? headlineImageStyle;
3537

38+
/// The preferred shape for banner ads, used for in-article banners.
39+
final BannerAdShape? bannerAdShape;
40+
3641
@override
3742
State<AdmobInlineAdWidget> createState() => _AdmobInlineAdWidgetState();
3843
}
@@ -107,11 +112,14 @@ class _AdmobInlineAdWidgetState extends State<AdmobInlineAdWidget> {
107112
NativeAdTemplateType.medium => 340,
108113
};
109114
} else if (widget.inlineAd is BannerAd) {
110-
// For banner ads, adjust height based on headlineImageStyle.
111-
// If largeThumbnail, assume mediumRectangle (300x250), otherwise standard banner (320x50).
112-
adHeight = widget.headlineImageStyle == HeadlineImageStyle.largeThumbnail
113-
? 250 // Height for mediumRectangle
114-
: 50;
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+
_ => 50, // Default to standard banner height if shape is null or unknown
122+
};
115123
} else {
116124
// Fallback height for unknown inline ad types.
117125
adHeight = 100;

0 commit comments

Comments
 (0)