Admob Widgets

A variety of widgets to use easily ad units of AdMob

Getting started

Android

Modify the AndroidManifest.xml adding the next

<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>

In application tag, add the next

<meta-data
    android:name="com.google.android.gms.ads.APPLICATION_ID"
    android:value="ca-app-pub-{your application ID}"/>

Finally in the main add the next code

void main() async{
  WidgetsFlutterBinding.ensureInitialized();
  AdMobWidgets.instance(
    androidBannerAdUnitId: "{Your banner ad unit Id}", 
    androidInterstitialAdUnitId: "Your intertitial ad unit Id"
    );
  await MobileAds.instance.initialize();
  runApp(const MainApp());
}

Usage

// Only call the widget
const BannerWidget();

Instertitial

// Initialize the the class InterstitialUnit
final interstitialUnit = InterstitialUnit();
// Initialize InterstitialAd
InterstitialAd? _interstitialAd;

@override
  void initState() {
    super.initState();
    // Load the ad
    interstitialUnit.loadAd();
  }

setState(() {
    //Asign the class's intertitial to local interstitial
      _interstitialAd = interstitialUnit.interstitialAd;
      // check interstital is not null
        if(_interstitialAd != null){
            // show the interstitial
          _interstitialAd!.show();
          // reload the interstitial
          interstitialUnit.loadAd();
        }
    });

Libraries

admob_widgets