Flutter Admob Adaptive Banner size Error (Empty Space in banner)

151 views Asked by At

Image in android app

I used an adaptive banner in my Flutter App (android), but the size is not right and the banner is not centered. (Empty Space exist in adaptive banner)

I used google_mobile_ads: 0.13.6

to fit adaptive banner I used codes in Doc

AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize( MediaQuery.of(context).size.width.truncate()

and here is my Code ...

< My adaptive Banner Code>

  Future<void> _loadAd(adunit) async {
    // Get an AnchoredAdaptiveBannerAdSize before loading the ad.
    final AnchoredAdaptiveBannerAdSize? size =
    await AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(
        MediaQuery.of(context).size.width.truncate());

    if (size == null) {
      print('Unable to get height of anchored banner.');
      return;
    }

    _anchoredAdaptiveAd = BannerAd(
      // TODO: replace these test ad units with your own ad unit.
      adUnitId: kReleaseMode 
          ? adunit 
          : 'ca-app-pub-3940256099942544/6300978111', 
      size: size,
      request: AdRequest(),
      listener: BannerAdListener(
        onAdLoaded: (Ad ad) {
          print('$ad loaded: ${ad.responseInfo}');
          setState(() {
            // When the ad is loaded, get the ad size and use it to set
            // the height of the ad container.
            _anchoredAdaptiveAd = ad as BannerAd;
            _isLoaded = true;
          });
        },
        onAdFailedToLoad: (Ad ad, LoadAdError error) {
          print('Anchored adaptive banner failedToLoad: $error');
          ad.dispose();
        },
      ),
    );
    return _anchoredAdaptiveAd!.load();
  }
return Scaffold(
      /// ★Body★
        body : SafeArea(
                child: Container(
                    width: double.infinity,
                    decoration: BoxDecoration(color: AppColors.white),
                    child: Padding(
                      padding: const EdgeInsets.all(5.0),
                      child: ListView(children: [
                        /// mainMenuButtons
                        mainMenuBox(),
                        /// ★adaptive banner★
                        if (_anchoredAdaptiveAd != null && _isLoaded)
                          Container(
                            color: Colors.green,
                            width: _anchoredAdaptiveAd!.size.width.toDouble(),
                            height: _anchoredAdaptiveAd!.size.height.toDouble(),
                            child: AdWidget(ad: _anchoredAdaptiveAd!),
                          ),
                        SizedBox(height: 20),
                        /// subMenu
                        subMenu(),
                      ]),
                    ))
            )
        )
    );
0

There are 0 answers