'(No implementation found for method _init on channel plugins.flutter.io/google_mobile_ads)

couldnt find anything wrong with it

dependencies:

 google_mobile_ads: ^1.1.0

Error:

MissingPluginException(No implementation found for method MobileAds#initialize on channel plugins.flutter.io/google_mobile_ads) at Object.throw_ [as throw] (http://localhost:58428/dart_sdk.js:5067:11) at platform_channel.MethodChannel.new._invokeMethod (http://localhost:58428/packages/flutter/src/services/restoration.dart.lib.js:1560:21) at _invokeMethod.next () at http://localhost:58428/dart_sdk.js:40571:33 at _RootZone.runUnary (http://localhost:58428/dart_sdk.js:40441:59) at _FutureListener.thenAwait.handleValue (http://localhost:58428/dart_sdk.js:35363:29) at handleValueCallback (http://localhost:58428/dart_sdk.js:35931:49) at Function._propagateToListeners (http://localhost:58428/dart_sdk.js:35969:17) at _Future.new.[_completeWithValue] (http://localhost:58428/dart_sdk.js:35817:23) at async._AsyncCallbackEntry.new.callback (http://localhost:58428/dart_sdk.js:35838:35) at Object._microtaskLoop (http://localhost:58428/dart_sdk.js:40708:13) at _startMicrotaskLoop (http://localhost:58428/dart_sdk.js:40714:13) at http://localhost:58428/dart_sdk.js:36191:9

AdsManager :

class AdsManager {
  static bool testMode = true;

  late InterstitialAd? interstitialAd;
  int numInterstitialLoadAttempts = 0;

  static String get rewardedAdUnitId {
    if (testMode == true) {
      return RewardedAd.testAdUnitId;
    } else if (Platform.isAndroid) {
      return "ca-app-pub-1571703103044065/4157175333";
    } else if (Platform.isIOS) {
      return "ca-app-pub-1571703103044065/4157175811";
    } else {
      throw UnsupportedError("Unsupported platform");
    }
  }

  static String get bannerAdUnitId {
    if (testMode == true) {
      return BannerAd.testAdUnitId;
    } else if (Platform.isAndroid) {
      return "ca-app-pub-1571703103044065/4157175333";
    } else if (Platform.isIOS) {
      return "ca-app-pub-1571703103044065/6858117501";
    } else {
      throw UnsupportedError("Unsupported platform");
    }
  }

  static String get interstitialAdUnitId {
    if (testMode == true) {
      return InterstitialAd.testAdUnitId;
    } else if (Platform.isAndroid) {
      return "ca-app-pub-1571703103044065/4157175333";
    } else if (Platform.isIOS) {
      return "ca-app-pub-1571703103044065/2885703588";
    } else {
      throw UnsupportedError("Unsupported platform");
    }
  }
}

in page.dart

class _HomePageState extends State<HomePage> {
  late RewardedAd _rewardedAd;
  late InterstitialAd interstitialAd;
  int numInterstitialLoadAttempts = 0;
  bool isRewardedAdReady = false;
  var _balance = 0;

  //Banner Ad

  late BannerAd _bannerAd;
  bool _adIsLoaded = false;

  @override
  void initState() {
    _initGoogleMobileAds();
    _loadRewardedAd();
    loadInterstitialAd();
    //
    _bannerAd = BannerAd(
        adUnitId: AdsManager.bannerAdUnitId,
        request: const AdRequest(),
        size: AdSize.banner,
        listener: BannerAdListener(
          onAdLoaded: (ad) {
            setState(() => _adIsLoaded = true);
          },
          onAdFailedToLoad: (ad, error) {
            setState(() => _adIsLoaded = false);
          },
        ));
    _bannerAd.load();
    //
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source