Anuncios do Admob no Flutter

pubspec.yaml

dependencies:
flutter:
sdk: flutter

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
firebase_admob: ^0.9.0+9

AndroidManifest.xml

<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="[ADMOB_APP_ID]"/>

Main

import 'package:firebase_admob/firebase_admob.dart';
 @override
Widget (BuildContext context) {
  FirebaseAdMob.instance.initialize(appId: "[ADMOB_APP_ID]");
  myBanner
..load()
..show(
anchorOffset: 60.0,
horizontalCenterOffset: 10.0,
anchorType: AnchorType.bottom,
);


myInterstitial
..load()
..show(
anchorType: AnchorType.bottom,
anchorOffset: 0.0,
horizontalCenterOffset: 0.0,
);

return Scaffold(

 
MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
keywords: <String>['games', 'game','Kids'],
contentUrl: 'https://flutter.io',
childDirected: false,
testDevices: <String>[], // Android emulators are considered test devices
);

BannerAd myBanner = BannerAd(
adUnitId: [Your Banner.Ad.Id],
size: AdSize.smartBanner,
targetingInfo: targetingInfo,
listener: (MobileAdEvent event) {
print("BannerAd event is $event");
},
);

InterstitialAd myInterstitial = InterstitialAd(
adUnitId: [Your Interstitial.Ad_Id],
targetingInfo: targetingInfo,
listener: (MobileAdEvent event) {
print("InterstitialAd event is $event");
},
);

 

2 comentários em “Anuncios do Admob no Flutter”

  1. Boa tarde,

    Primeiramente Muito bom seu vídeo, parabéns,

    Eu tentei reproduzir ele mas estou obtendo E/flutter (24914): PlatformException(load_failed_ad, cannot reload a failed ad, id=XXXXX, null)

    Saberia como resolver?

    Responder
    • Olá Rafael.
      Esse erro costuma acontecer logo no início após a configuração.
      Passado algumas horas, já começa a encontrar os anuncios.
      Abraço, boa programação

      Responder

Deixe um comentário