Skip to content

Commit 582335a

Browse files
committed
feat(ads): add bannerAdShape parameter to LocalBannerAdWidget
- Add optional BannerAdShape parameter to LocalBannerAdWidget constructor - Use bannerAdShape to determine ad height instead of headlineImageStyle - Implement switch case for determining image height based on bannerAdShape - Update documentation to reflect new parameter and its usage
1 parent d2de638 commit 582335a

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/ads/widgets/local_banner_ad_widget.dart

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,32 @@ class LocalBannerAdWidget extends StatelessWidget {
1010
const LocalBannerAdWidget({
1111
required this.localBannerAd,
1212
this.headlineImageStyle,
13+
this.bannerAdShape,
1314
super.key,
1415
});
1516

1617
/// The [LocalBannerAd] to display.
1718
final LocalBannerAd localBannerAd;
1819

1920
/// The user's preference for feed layout, used to determine the ad's visual size.
21+
/// This is only relevant for native ads.
2022
final HeadlineImageStyle? headlineImageStyle;
2123

24+
/// The preferred shape for banner ads, used for in-article banners.
25+
final BannerAdShape? bannerAdShape;
26+
2227
@override
2328
Widget build(BuildContext context) {
2429
final theme = Theme.of(context);
2530

26-
// Determine the height based on the headlineImageStyle.
27-
// If largeThumbnail, use a square aspect ratio, otherwise a standard banner height.
28-
final imageHeight = headlineImageStyle == HeadlineImageStyle.largeThumbnail
29-
? 250
30-
: 90;
31+
// Determine the height based on the bannerAdShape if provided.
32+
// If bannerAdShape is square, use height for mediumRectangle (250).
33+
// Otherwise, use height for standard banner (90).
34+
final imageHeight = switch (bannerAdShape) {
35+
BannerAdShape.square => 250,
36+
BannerAdShape.rectangle => 90,
37+
_ => 90, // Default to standard banner height if shape is null or unknown
38+
};
3139

3240
return Card(
3341
margin: const EdgeInsets.symmetric(

0 commit comments

Comments
 (0)