3

I am following a tutorial of adding a Banner Ad. But for me it gives this error.

The getter 'testAdUnitID' isn't defined for the type 'BannerAd'. 

Is testAdUnitID is deprecated or something? What's the way out?

My code is:

  void _initBannerAd() {
    _bannerAd = BannerAd(
      size: AdSize.banner,
      adUnitId: BannerAd.testAdUnitID,
      listener: BannerAdListener(),
      request: AdRequest(),
    );
  }

Here is the screenshot:

Screenshot

My Car
  • 4,198
  • 5
  • 17
  • 50
Saad Mansoor
  • 199
  • 7

1 Answers1

4

Which tutorial did you watch?

edit

found update log here.

https://pub.dev/packages/google_mobile_ads/changelog

  • 2.0.0
    • Removes static testAdUnitId parameters. See the Admob and AdManager documentation for up to date test ad units.

solution

you can get some test id for adUnitId from here.

https://developers.google.com/admob/android/test-ads

and flutter sample here.

https://developers.google.com/admob/flutter/test-ads

rodpold
  • 156
  • 6
  • 1
    I was watching this video. @ video timestamp: 3:00 here is the link: https://www.youtube.com/watch?v=WIp5ATit_d0&t=2s&ab_channel=CodeX – Saad Mansoor Nov 22 '22 at 10:36
  • I still dont understand why testAdUnitID' was error prone. However, I got to know that 'adUnitId' property accepts a string. So, I solved it by giving hard coded string of testing banner ad, e.g. (ca-app-pub-3940256099942544/6300978111). instead of writing BannerAd.testAdUnitId. – Saad Mansoor Nov 22 '22 at 10:39
  • 1
    Ok. I found you using google_mobile_ads from your video. And also found removed update log here. https://pub.dev/packages/google_mobile_ads/changelog 2.0.0 – rodpold Nov 22 '22 at 15:29