Skip to content

Commit cc45256

Browse files
committed
refactor(ads): improve ad image height determination
- Prioritize bannerAdShape for in-article context - Use headlineImageStyle for feed context when bannerAdShape is null - Enhance code readability and maintainability
1 parent f2c0cfd commit cc45256

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

lib/ads/widgets/local_banner_ad_widget.dart

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

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-
};
31+
// Determine the height. Prioritize bannerAdShape for in-article context.
32+
// Fall back to headlineImageStyle for feed context.
33+
final int imageHeight;
34+
if (bannerAdShape != null) {
35+
imageHeight = switch (bannerAdShape) {
36+
BannerAdShape.square => 250,
37+
BannerAdShape.rectangle => 90,
38+
_ => 90,
39+
};
40+
} else {
41+
imageHeight = headlineImageStyle == HeadlineImageStyle.largeThumbnail
42+
? 250
43+
: 90;
44+
}
3945

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

0 commit comments

Comments
 (0)