googleads / googleads-mobile-flutter

A Flutter plugin for the Google Mobile Ads SDK
Apache License 2.0
339 stars 280 forks source link

Uncertain Banner Height with AdManagerBannerAd and List<AdSize> #1116

Closed goodiny777 closed 2 months ago

goodiny777 commented 3 months ago

Description:

The AdManagerBannerAd class in the Google Mobile Ads Flutter plugin (https://pub.dev/packages/google_mobile_ads) allows specifying multiple ad sizes through a List parameter in the constructor. However, there's currently no way to determine the exact size of the ad returned after loading.

Problem:

Flutter widgets typically expect a defined height, often set to double.infinity for flexible layouts. This becomes problematic when using AdManagerBannerAd with List. Since the actual ad size is unknown beforehand, setting the container's height to double.infinity can lead to unintended layout issues or wasted space.

Request:

Enhance AdManagerBannerAd: Introduce a method, potentially getLoadedAdSize(), that retrieves the actual size of the loaded ad after a successful load() call. This would allow developers to set the container height dynamically based on the returned AdSize. Alternative Approach: If retrieving the exact size isn't feasible, consider providing a way to specify a preferred height alongside the List. This value could be used as a fallback or a maximum height constraint for the banner ad. Impact:

Currently, using AdManagerBannerAd with multiple sizes can lead to:

Layout Issues: Incorrect sizing or wasted space in the container due to an unknown ad height. Workarounds: Developers resorting to hardcoded heights or complex calculations to estimate the ad size, leading to less maintainable code.

By providing a solution to this limitation, the plugin would offer greater flexibility and improve the user experience for developers working with AdManager banners in Flutter applications

malandr2 commented 3 months ago

Hi @goodiny777, have you tried using getInlineAdaptiveBannerAdSize API?

goodiny777 commented 3 months ago

getInlineAdaptiveBannerAdSize

Hi @malandr2, yes I've tryed this api but it is not good for us when we want to use fluid banner. As I described above in natice we have option to send all the expected sizes include fluid and we are recieving all as expected. But in flutter the only class that allows to do so is AdManagerBannerAd but then we have AdWidget with height = double.infinity than cant be changed.

malandr2 commented 3 months ago

Hi @goodiny777, have you tried setting the height/width to the size of the ad? See our banner guide(s) for more examples.

goodiny777 commented 3 months ago

Hi @goodiny777, have you tried setting the height/width to the size of the ad? See our banner guide(s) for more examples.

Yes of course, @malandr2 , but when I use AdManagerBannerAd with list of sizes after I receive ad view I don't know exact height of the coming banner

malandr2 commented 3 months ago

Hi @goodiny777, you should use getPlatformAdSize(). Please see the code example in our adaptive banner guide to know the exact size of the loaded banner

malandr2 commented 3 months ago

If you are still having issues, please provide a minimal, reproducible sample so I can take a closer look. Thanks!

malandr2 commented 2 months ago

Closing due to inactivity.