导航到下一页时如何隐藏横幅广告?

Ama*_*tam 15 ads admob flutter

我正在使用firebase_admob插件在 flutter 应用程序中设置广告。我尝试了横幅广告,它工作正常,但是,当我导航到另一个页面时,它仍然保持在原来的位置。我希望在导航到另一个页面时该广告应该隐藏。

代码片段如下。

BannerAd myBanner = BannerAd(
  // Replace the testAdUnitId with an ad unit id from the AdMob dash.
  // https://developers.google.com/admob/android/test-ads
  // https://developers.google.com/admob/ios/test-ads
  adUnitId: BannerAd.testAdUnitId,
  size: AdSize.smartBanner,
  targetingInfo: targetingInfo,
  listener: (MobileAdEvent event) {
    print("BannerAd event is $event");
  },
);
myBanner
  // typically this happens well before the ad is shown
  ..load()
  ..show(
    // Positions the banner ad 60 pixels from the bottom of the screen
    anchorOffset: 60.0,
    // Banner Position
    anchorType: AnchorType.bottom,
  );
Run Code Online (Sandbox Code Playgroud)

Jit*_*ude 1

dispose()当页面被销毁时将被调用。所以你可以在那里销毁横幅广告。

  @override
  void dispose() {

    myBanner.dispose();

    super.dispose();
  }
Run Code Online (Sandbox Code Playgroud)