Search code examples
flutterdartadmobadsbanner-ads

Is BannerAd.testAdUnitID is out dated?


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


Solution

  • 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