I am using google_mobile_ads: ^3.0.0 on flutter.
Please see the attached image. The issue is ad does not fill up the entire area. It looks odd. Is there a plan to fix this issue anytime soon?
My code below.
class AdBanner extends StatefulWidget {
const AdBanner({Key? key}) : super(key: key);
@override
State<AdBanner> createState() => _AdBannerState();
}
class _AdBannerState extends State<AdBanner> {
BannerAd? _inlineAdaptiveAd;
bool _isLoaded = false;
@override
void initState() {
super.initState();
_loadAd();
}
void _loadAd() async {
await _inlineAdaptiveAd?.dispose();
// Get an inline adaptive size for the current orientation.
AdSize size = AdSize.banner;
//if (width >= 468) size = AdSize.fullBanner;
//if (width >= 728) size = AdSize.leaderboard;
_inlineAdaptiveAd = BannerAd(
adUnitId: AdHelper.bannerAdUnitId,
size: size,
request: const AdRequest(),
listener: BannerAdListener(
onAdLoaded: (Ad ad) async {
debugPrint('Inline adaptive banner loaded: ${ad.responseInfo}');
// After the ad is loaded, get the platform ad size and use it to
// update the height of the container. This is necessary because the
// height can change after the ad is loaded.
//BannerAd bannerAd = (ad as BannerAd);
// _finalSize = await bannerAd.getPlatformAdSize();
// if (size == null) {
// debugPrint(
// 'Error: getPlatformAdSize() returned null for $bannerAd');
// return;
// }
if (mounted) {
setState(() {
//_inlineAdaptiveAd = bannerAd;
_isLoaded = true;
});
}
},
onAdFailedToLoad: (Ad ad, LoadAdError error) {
debugPrint('Inline adaptive banner failedToLoad: $error');
_isLoaded = false;
ad.dispose();
},
),
);
await _inlineAdaptiveAd!.load();
}
@override
Widget build(BuildContext context) {
return (_isLoaded && _inlineAdaptiveAd != null)
? Align(
alignment: Alignment.bottomCenter,
child: SizedBox(
width: _inlineAdaptiveAd!.size.width.toDouble(),
height: _inlineAdaptiveAd!.size.height.toDouble(),
child: AdWidget(
ad: _inlineAdaptiveAd!,
)))
: const SizedBox(
width: 0,
height: 0,
);
}
@override
void dispose() {
_inlineAdaptiveAd?.dispose();
super.dispose();
}
}