Error that I am getting. I have seen other MissingPluginExeptions, but none for firebase_admob.
[VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method loadInterstitialAd on channel plugins.flutter.io/firebase_admob)
#0 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:319:7)
<asynchronous suspension>
#1 _invokeBooleanMethod (package:firebase_admob/firebase_admob.dart:611:61)
#2 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:45:6)
#3 _invokeBooleanMethod (package:firebase_admob/firebase_admob.dart:610:34)
#4 InterstitialAd.load (package:firebase_admob/firebase_admob.dart:377:12)
#5 _personSettingsState.initState (package:randompersonapp/personSettings.dart:68:45)
#6 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4355:58)
#7 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#8 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#9 Element.updateChild (package:flutter/src/widg<…>
These are the processes I have tried. I get no errors from the flutter doctor.
flutter clean
flutter doctor
flutter run
This is the code I am using to get the error. It is inside a stateful widget, but I can't show all of it because it is in production code.
import 'dart:math';
import 'package:firebase_admob/firebase_admob.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
InterstitialAd myInterstitial;
InterstitialAd buildInterstitialAd() {
return InterstitialAd(
adUnitId: InterstitialAd.testAdUnitId,
listener: (MobileAdEvent event) {
if (event == MobileAdEvent.failedToLoad) {
myInterstitial..load();
} else if (event == MobileAdEvent.closed) {
myInterstitial = buildInterstitialAd()..load();
}
print(event);
},
);
}
void showInterstitialAd() {
myInterstitial..show();
}
void showRandomInterstitialAd() {
Random r = new Random();
bool value = r.nextBool();
if (value == true) {
myInterstitial..show();
}
}
@override
void initState() {
myInterstitial = buildInterstitialAd()..load();
super.initState();
}
@override
void dispose() {
myInterstitial.dispose();
super.dispose();
}
I have made two apps in firebase and linked them with the app id in the appmanifest for Android and info.plist for IOS. The Error points to the line
myInterstitial = buildInterstitialAd()..load();
Anyone have any tips? I am open to any suggestions or thoughts on the matter.
if you are with this problem: First: add this in android manifest
<manifest>
<application>
<!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="[ADMOB_APP_ID]"/>
</application>
</manifest>
Second: When you add something in android manifest, you need close the app (stop the simulation) and start again to android manifest refresh.
PS: do not forget to add this in app/build.gradle:
implementation 'com.google.firebase:firebase-ads:18.0.0'