google_applovin_unity_ads 2.2.0 copy "google_applovin_unity_ads: ^2.2.0" to clipboard
google_applovin_unity_ads: ^2.2.0 copied to clipboard

Ads Implement

ADD IN PUBSPEC.YMAL #

dependencies:
google_applovin_unity_ads:
get:
flutter_screenutil:
visibility_detector: ^0.3.3

ADD IN ANDROID MANIFEST #


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

<applicaton
<meta-data
android:name="com.google.android.gms.ads.AD_MANAGER_APP"
android:value="true" />

//FOR ANDROID SPLASH SCREEN
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background" />
</application>

ADD IN BUILD GRADEL #

    multiDexEnabled true
    targetSdkVersion 33

ADD IN VOID MAIN #

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  MobileAds.instance.initialize();
  runApp(const MyApp());
}

INITIALISE ADS FIRST TIME #


@override
void initState() {
  // TODO: implement initState
  super.initState();
  fetchAdsSettings(
      appVersionCode: 1,
      settingsUrl:
      "https://gitlab.com/pp.bitcoding/demotest/-/raw/main/test.json",
      keyName: "com.bitlinks.arebic.iptv.m3ulist")
      .then((value) =>
  {
    initOpenAds(onOpenAdLoaded: () => {showOpenAds()}),
    if(value?.adsSequence?.contains("app_lovin") ?? false)
      {
        if ((getAdsSettings()?.appLovin?.sdkKey ?? "").isNotEmpty)
          {
            AppLovinAds.instance
                .initialize(value!.appLovin!.sdkKey!)
                .then((value) =>
            {
              YOUR PAGE ROUTE
            })
          }
        else
          {
            YOUR PAGE ROUTE
          }
      }
    else
      {
        YOUR PAGE ROUTE
      }
  });
}

FOR OPEN AD #

    initOpenAds(onOpenAdLoaded: () => {showOpenAds()}),

FOR INTRA AD #

    showIntraAds(callback: () => {});

FOR REWARD AD #

    showRewardAds(callback: () => {});

FOR BANNER AD #


  Widget bannerShow = Container(height: 0);
  var adSizeBanner = AdSize.largeBanner;         -> medium height.
  var adSizeBanner = AdSize.mediumRectangle;     -> full height.
  var adSizeBanner = AdSize.banner;              -> small height.
  
  
  <--------load native ad -------->
  
    showBannerAds(
      size: adSiiize,
      onAdLoadedCallback: (p0) {
        setState(() {
          bannerShow = p0;
        });
      },
    );
    
    
 <--------show native ad -------->
      bannerShow,
 

NATIVE ADS #

ADD IN MAINACTIVITY.KT

import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import com.btcpiyush.ads.google_applovin_unity_ads.CustomNativeAd
import com.btcpiyush.ads.google_applovin_unity_ads.GoogleApplovinUnityAdsPlugin

class MainActivity: FlutterActivity() {
    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)
        val factory: CustomNativeAd =
            CustomNativeAd(
                getLayoutInflater()
            )
        GoogleApplovinUnityAdsPlugin.registerNativeAdFactory(flutterEngine, "nativeFactoryId", factory)
    }

    override fun cleanUpFlutterEngine(flutterEngine: FlutterEngine) {
        GoogleApplovinUnityAdsPlugin.unregisterNativeAdFactory(flutterEngine, "nativeFactoryId")
    }
}

SMALL NATIVE #

 Widget smallNativeShow = Container(
    height: 0,
  );
  
  <--------load native ad -------->
  
  showMediumNativeAds(
        onAdLoadedCallback: (a) => {
              setState(() {
                smallNativeShow = a;
              })
            });
  
  <--------show native ad -------->
  smallNativeShow,
  

BIG NATIVE #


  Widget BigNativeShow = Container(
    height: 0,
  );

  <--------load native ad -------->
   showNativeAds(
        onAdLoadedCallback: (a) => {
              setState(() {
                BigNativeShow = a;
              })
            });
            
            
  <--------show native ad -------->            
            BigNativeShow,

LISTVIEW BUILDER ADS (banner ads / native ads) #



AdsController.instance.widgetlist.addAll(add your list);

showAdsInListView(
        isNativeAds: true,
        bannerSize: AdSize.mediumRectangle,
        adsDistance: 30,
        itemBuilder: (context, index) {
          Widget widget = Container(
          height: 0,
    );

      if (AdsController.instance.widgetlist[index] != null &&
      AdsController.instance.widgetlist[index] is String  // check datatype) {
      widget =  your design here
      }

        return VisibilityDetector(
        key: Key(index.toString()),
        onVisibilityChanged: (VisibilityInfo info) {
        if (info.visibleFraction == 1) {
        AdsController.instance.currentIndex.value = index;
        }
        },
        child: widget);
        },
        controller: AdsController.instance)

GRIDVIEW BUILDER ADS (banner ads / native ads) #

showAdsInGridView(
isNativeAds: true,                          if true -> native ads else banner ads show.
bannerSize: AdSize.mediumRectangle,
list: AdsController.instance.widgetlist,
adsDistance: 3,
itemBuilder: (context, index) {
return Text("Pragnesh ${index}");
},
controller: AdsController.instance)