Skip to content

Commit ee4b4ba

Browse files
committed
feat(ads): enhance demo banner ad widget with banner ad shape
- Add bannerAdShape parameter to DemoBannerAdWidget - Implement logic to determine ad height based on bannerAdShape - Update ad height calculation to use switch expression - Add support for square and rectangle banner ad shapes
1 parent 1a68956 commit ee4b4ba

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lib/ads/widgets/demo_banner_ad_widget.dart

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,26 @@ import 'package:ui_kit/ui_kit.dart';
1111
/// {@endtemplate}
1212
class DemoBannerAdWidget extends StatelessWidget {
1313
/// {@macro demo_banner_ad_widget}
14-
const DemoBannerAdWidget({this.headlineImageStyle, super.key});
14+
const DemoBannerAdWidget({this.headlineImageStyle, this.bannerAdShape, super.key});
1515

1616
/// The user's preference for feed layout, used to determine the ad's visual size.
1717
final HeadlineImageStyle? headlineImageStyle;
1818

19+
/// The preferred shape for banner ads, used for in-article banners.
20+
final BannerAdShape? bannerAdShape;
21+
1922
@override
2023
Widget build(BuildContext context) {
2124
final theme = Theme.of(context);
2225

23-
// Determine the height based on the headlineImageStyle, mimicking real ad widgets.
24-
final adHeight = headlineImageStyle == HeadlineImageStyle.largeThumbnail
25-
? 250 // Height for mediumRectangle banner
26-
: 50; // Height for standard banner
26+
// Determine the height based on the bannerAdShape if provided.
27+
// If bannerAdShape is square, use height for mediumRectangle (250).
28+
// Otherwise, use height for standard banner (50).
29+
final adHeight = switch (bannerAdShape) {
30+
BannerAdShape.square => 250,
31+
BannerAdShape.rectangle => 50,
32+
_ => 50, // Default to standard banner height if shape is null or unknown
33+
};
2734

2835
return Card(
2936
margin: const EdgeInsets.symmetric(

0 commit comments

Comments
 (0)