Skip to content

Commit b9ba612

Browse files
committed
fix(ads): implement AdWidget height constraints for native ads
- Wrap AdWidget in a SizedBox to provide explicit height constraints - Assign heights based on native ad template types (small, medium) - Prevents "unbounded height" errors for native ads in scrollable lists
1 parent b2908cd commit b9ba612

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/ads/widgets/admob_native_ad_widget.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ class AdmobNativeAdWidget extends StatelessWidget {
3636

3737
// The AdWidget from the google_mobile_ads package handles the rendering
3838
// of the pre-loaded native ad.
39-
return admob.AdWidget(ad: adObject);
39+
// We wrap it in a SizedBox to provide explicit height constraints,
40+
// which is crucial for platform views (like native ads) within scrollable
41+
// lists to prevent "unbounded height" errors.
42+
final adHeight = switch (nativeAd.templateType) {
43+
app_ad_models.NativeAdTemplateType.small => 120, // Example height for small template
44+
app_ad_models.NativeAdTemplateType.medium => 340, // Example height for medium template
45+
};
46+
47+
return SizedBox(
48+
height: adHeight.toDouble(),
49+
child: admob.AdWidget(ad: adObject),
50+
);
4051
}
4152
}

0 commit comments

Comments
 (0)