question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BannerAd.size retrieving only -1

See original GitHub issue

Bug report

Describe the bug I am trying to retrieve the correct size of Banner but the methods BannerAd.size.height/width gives me the value -1.

Steps to reproduce


  static BannerAd _bannerAd;
  static Future<Widget> getBannerWidget({AdSize adSize}) async{

    _bannerAd = BannerAd(
      adUnitId: getBannerAdUnitId(),
      size: adSize ?? AdSize.smartBanner,
      request: _adRequest,
      listener: AdListener(
        // Called when an ad is successfully received.
        onAdLoaded: (Ad ad) {

          if(_debug){
            print('Ad loaded.');
          }

        },
        // Called when an ad request failed.
        onAdFailedToLoad: (Ad ad, LoadAdError error) {

          if(_debug){
            print('Ad failed to load: $error');
            _bannerAd.dispose();
          }

        },
        // Called when an ad opens an overlay that covers the screen.
        onAdOpened: (Ad ad) {

          if(_debug){
            print('Ad opened.');
          }

        },
        // Called when an ad removes an overlay that covers the screen.
        onAdClosed: (Ad ad) {

          if(_debug){
            print('Ad closed.');
          }

        },
        // Called when an ad is in the process of leaving the application.
        onApplicationExit: (Ad ad) {

          if(_debug){
            print('Left application.');
          }

        },
      ),
    );

    await _bannerAd.load();

    print("BANNER SIZE HEIGHT: ${_bannerAd.size.height}"); // -1
    print("BANNER SIZE WIDTH: ${_bannerAd.size.width}"); // -1

    return Container(
        child: AdWidget(ad: _bannerAd),
        height: _bannerAd.size.height,
        width: _bannerAd.size.width,
    );

  }

Expected behavior

Retrieve the correct size of the loaded banner.


Additional context

Add any other context about the problem here.


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand
[√] Flutter (Channel stable, 2.0.0, on Microsoft Windows [versão 10.0.19042.844], locale pt-BR)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.8.5)
[√] Android Studio (version 4.1.0)
[√] VS Code (version 1.53.2)
[√] Connected device (4 available)

• No issues found!


Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand
Dart SDK 2.12.0
Flutter SDK 2.0.0
djalma_ads 0.2.8

dependencies:
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
- google_mobile_ads 0.11.0+1 [meta flutter]

dev dependencies:
- flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_s
pan stream_channel string_scanner term_glyph typed_data]

transitive dependencies:
- async 2.5.0 [collection]
- boolean_selector 2.1.0 [source_span string_scanner]
- characters 1.1.0
- charcode 1.2.0
- clock 1.1.0
- collection 1.15.0
- fake_async 1.2.0 [clock collection]
- matcher 0.12.10 [stack_trace]
- meta 1.3.0
- path 1.8.0
- sky_engine 0.0.99
- source_span 1.8.0 [charcode collection path term_glyph]
- stack_trace 1.10.0 [path]
- stream_channel 2.1.0 [async]
- string_scanner 1.1.0 [charcode source_span]
- term_glyph 1.2.0
- test_api 0.2.19 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher]
- typed_data 1.3.0 [collection]
- vector_math 2.1.0


Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:14
  • Comments:5

github_iconTop GitHub Comments

8reactions
AnkitChowdhurycommented, Mar 5, 2021

If I may add to it, the problem is only occurring for SmartBanners. Other forms of banners are reporting the size values correctly.

2reactions
Puruscommented, Apr 6, 2021

Unable to use Smart Banners because of this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Banner Ad Sizes: All You Need to Know - Kinsta
Check out the most common and best-performing banner ad sizes for all the major networks (Google, Facebook, Instagram).
Read more >
What Are The Standard Banner Ad Sizes in 2022 - Creatopy
Here are the top 5 performing banner ad sizes in 2022 that can help you ... At the same time, it's a good...
Read more >
Banner Ads | Android - Google Developers
Needs 320x50 dp, but only has 288x495 dp. The table below lists the standard banner sizes. Size in dp (WxH), Description, Availability ...
Read more >
Guide to Banner Ad Sizes For Google Ads, Facebook ...
You get a number of options to design customized and responsive display ads in different sizes. Here's an image showing the top banner...
Read more >
Determine banner ad size on android - Stack Overflow
I want to reduce the height of my view so as to make space for the banner in bottom. But, I am not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found