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

Ads Implement

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:google_applovin_unity_ads/google_applovin_unity_ads.dart';
import 'package:google_applovin_unity_ads/native/controller.dart';
import 'package:google_applovin_unity_ads_example/second_page.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: Size(double.infinity, double.infinity),
      minTextAdapt: true,
      splitScreenMode: true,
      builder: (context, child) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: const MyHomePage(title: 'Flutter Demo Home Page'),
        );
      },
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();

}

class _MyHomePageState extends _OpenAdState<MyHomePage> {

  String loadAdMob = "";
  String showAdMob = "";
  Widget nativeAd = Container(
    height: 0,
  );

  void afteradsCallback() {
    print("Callback completed after ad function");
  }

  Future<void> _loadAds() async {
    // GoogleApplovinUnityAds.showRewardAds(callback: afteradsCallback);
    setState(() {
      nativeAd = GoogleApplovinUnityAds.bannerAds();
    });
  }

  @override
  void initState() {
    super.initState();
    GoogleApplovinUnityAds.initialize("""
   {
   "ads_sequence": [
			"app_lovin"
	],	
	"more_app_url": "https://play.google.com/store/apps/developer?id=Bit+Links", 	
	"extra_url": "https://gitlab.com/bitcodingsolutions/iptv_channels/-/raw/main/allcountrylist.json",
	"iptv_player_url": "com.pocketiptv",
	"ad_setting": {	

		"app_version_code": 7,

		"is_full_ads": false,
		"onesignal_id": "07de0128-c4bc-45f0-8baa-6867a262a6b7", 
		"ads_loading_text": "Ads will loading...",
		"global_intra_interval_click": 5,
		"interstitial_ad_time_interval": 1,
		"native_ad_list_interval": 4
	},	
	"app_update": {	
		"is_popup_dialog": false,
		"is_update_require": false,
		"package_id": "com.yoyolive.llc", 
		"website_url": "https://play.google.com/store/apps/details?id=com.yoyolive.llc", 
		"app_icon": "https://i.postimg.cc/KvDBRzS1/YOYO.png",
		"updated_version_code": 50,
		"title": "YoYo Random Video call",
		"default_message": "Random Video calling around the Whole world"
	},	
	"exit_dialog": {	
		"is_exit_require": true,
		"exit_title": "Exit",
		"exit_message": "Do you want to exit from App?"
	},
	"reward_dialog": {	
		"is_reward_require": true,
		"reward_message": "Watch Reward ads for More Random Video call"
   	 },	
	"About_App": {	
		"is_override": false,
		"is_about_app": true,
		"about_title": "IPTV : World m3u playlists", 
		"about_message": "Your app is Up to date!",
		"registration_detail": "IPTV : World m3u playlists", 
		"version_detail": "version : 1.0.0"
	},	
	"rate_app": {	
		"is_rate_app": true,
		"package_id": "com.iptv.m3u.playlists", 
		"rate_app_url": "https://play.google.com/store/apps/details?id=com.iptv.m3u.playlists", 
		"rate_message": "Please Rate us and promote us."
	},	
	"share_app": {	
		"is_share_app": true,
		"share_title": "Share link url :https://play.google.com/store/apps/details?id=com.iptv.m3u.playlists", 
		"share_message": "Now anyone can get Livetalk : Random ideo calling app : https://play.google.com/store/apps/details?id=com.iptv.m3u.playlists" 
	},	
	"privacy_policy": {	
		"is_privacy_policy": true,
		"is_system_browser": true,
		"privacy_policy": "https://pages.flycricket.io/iptv-world-m3u-pla/privacy.html" 
	},	
	"terms_of_use": {	
		"is_terms_of_use": true,
		"is_system_browser": true,
		"terms_of_use": "https://pages.flycricket.io/iptv-world-m3u-pla/privacy.html" 
	},	
	"error_report": {	
		"is_error_report_support": true,
		"email_id": "mailto: bitlinks.llc@gmail.com"
	},	
	"feedback_support": {	
		"is_feedback_support": true,
		"email_id":"mailto:bitlinks.llc@gmail.com",
		"feedback_title": "Feedback on IPTV : World m3u playlists",
		"feedback_message": "Hi,\n\n\nYour Feedback IPTV : World m3u playlists! I would like to give you some feedback:",
		"email_subject": "Feedback on IPTV : World m3u playlists",
		"email_message": "Hi,\n\n\nYour Feedback IPTV : World m3u playlists! I would like to give you some feedback:"
		
	},	
	"google_ads": {	
		"banner_ad_unit_id_android": "/6499/example/banner",
		"interstitial_ad_unit_id_android": "/6499/example/interestial",
		"app_open_ad_unit_id_android": "/6499/example/open",
		"native_ads_unit_id_android": "/6499/example/native",
		"rewared_ads_unit_id": "/6499/example/reward",
		"native_video_ads_unit_id_android": "/6499/example/native_video",
		"is_banner_ads": true,
		"is_open_ads": true,
		"is_interstitial_ads": true,
		"is_rewared_ads": true,
		"is_native_ads": true,
		"no_of_click_interstitial": 1
	},

	"facebook_ads": {	
		"banner_ad_unit_id_android": "604892471257569_604892857924197", 
		"interstitial_ad_unit_id_android": "604892471257569_604892931257523", 
		"rewared_ads_unit_id": "604892471257569_604893267924156", 
		"native_ads_unit_id_android": "IMG_16_9_APP_INSTALL#YOUR_PLACEMENT_ID", 
		"is_banner_ads": true,
		"is_interstitial_ads": true,
		"is_rewared_ads": true,
		"is_native_ads": true,
		"no_of_click_interstitial": 1
	},
	
	
	"custom_ads": {	
		"qureka_link": "https://490.go.qureka.com/intro/question",
		"is_quraka_banner": true,
		"is_quraka_intera": true,
		"close_button_to_direct_web": true,
		"quraka_intra_image": [
		"https://github.com/pragneshpalsanabitcoding/image_quraka/blob/main/360X640_1.png?raw=true",
		"https://github.com/pragneshpalsanabitcoding/image_quraka/blob/main/360X640_2.png?raw=true",
		"https://github.com/pragneshpalsanabitcoding/image_quraka/blob/main/360X640_3.png?raw=true",
		"https://github.com/pragneshpalsanabitcoding/image_quraka/blob/main/360X640_4.png?raw=true",
		"https://github.com/pragneshpalsanabitcoding/image_quraka/blob/main/360X640_5.png?raw=true",
		"https://github.com/pragneshpalsanabitcoding/image_quraka/blob/main/360X640_6.png?raw=true"
	],	
	"quraka_banner_image": [	
		"https://github.com/pragneshpalsanabitcoding/image_quraka/blob/main/2.jpg?raw=true",
		"https://github.com/pragneshpalsanabitcoding/image_quraka/blob/main/3.jpg?raw=true",
		"https://github.com/pragneshpalsanabitcoding/image_quraka/blob/main/320x50.jpg?raw=true",
		"https://github.com/pragneshpalsanabitcoding/image_quraka/blob/main/4.jpg?raw=true",
		"https://github.com/pragneshpalsanabitcoding/image_quraka/blob/main/5.jpg?raw=true",
		"https://github.com/pragneshpalsanabitcoding/image_quraka/blob/main/6.jpg?raw=true"
	]	
	},	
	"app_lovin": {	
    "sdk_key": "l2eHJCxgHTn4tTHns3A55HzXG6ekoyDJigM2SxRmGSN6T1bNmT37tTDW0UxVBVkUepJxXKxFQ8yPMONBdyKO3A",
		"is_unlimited_ads": false,		
		"id_unit_banner": "def1da1bf25084e",
		"id_unit_intra": "9657b7aa7d1430b",
		"id_unit_native_multiple": 
				{
     			        "small":"1d7452a63e76862",
      		        	"medium":"f330bac72f3dbf9",
    			        "manual":"42a7734a713d7f5"
  				},
		"rewared_ads_unit_id": "deda40e3d0a2840",
		"is_banner_ads": true,
		"is_interstitial_ads": true,
		"is_native_ads": true,
		"is_rewared_ads": true
	}	
	}
    """, callback: () => {print(" ---  ----- Initialize Callback()")});
  }

  @override
  void dispose() {
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }

  openAdCallback(){
    print("CHECK openAdCallback -------------------------- ");
    isAdShow = true;
    Navigator.of(context)
        .push(MaterialPageRoute(
      builder: (context) => SecondPage(),
    ));
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    if (state == AppLifecycleState.resumed) {
      print("CHECK On Resumed Called");
      if(!isAdShow)
        GoogleApplovinUnityAds.showOpenAds(callback: () => {
          openAdCallback()
        });
    }

    if (state == AppLifecycleState.paused) {
      print("CHECK On Paused Called");
      isAdShow = false;
    }
  }

  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context);
    return SafeArea(
        child: Column(
      mainAxisSize: MainAxisSize.max,
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Container(
            margin: EdgeInsets.all(8.0),
            width: double.infinity,
            height: 60,
            child: Material(
              color: Colors.transparent,
              child: InkWell(
                borderRadius: BorderRadius.all(Radius.circular(10)),
                onTap: () => _loadAds(),
                child: Ink(
                  child: Container(
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.all(Radius.circular(10)),
                      color: Colors.black,
                    ),
                    alignment: Alignment.center,
                    child: Padding(
                      padding: EdgeInsets.symmetric(vertical: 16.0),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Text("Show Native Ads",
                              style: TextStyle(
                                  fontSize: 20,
                                  fontWeight: FontWeight.bold,
                                  color: Colors.white)),
                        ],
                      ),
                    ),
                  ),
                ),
              ),
            )),
        nativeAd
      ],
    ));

    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        ),
        body: Center(
          // Center is a layout widget. It takes a single child and positions it
          // in the middle of the parent.
          child: Column(
            mainAxisSize: MainAxisSize.min,
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Container(
                  margin: EdgeInsets.all(8.0),
                  width: double.infinity,
                  height: 60,
                  child: Material(
                    color: Colors.transparent,
                    child: InkWell(
                      borderRadius: BorderRadius.all(Radius.circular(10)),
                      onTap: () => _loadAds(),
                      child: Ink(
                        child: Container(
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.all(Radius.circular(10)),
                            color: Colors.black,
                          ),
                          alignment: Alignment.center,
                          child: Padding(
                            padding: EdgeInsets.symmetric(vertical: 16.0),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Text("Show Intrestial Ads",
                                    style: TextStyle(
                                        fontSize: 20,
                                        fontWeight: FontWeight.bold,
                                        color: Colors.white)),
                              ],
                            ),
                          ),
                        ),
                      ),
                    ),
                  )),
              SizedBox(height: 24.h),
              /*Container(
                  margin: EdgeInsets.all(8.0),
                  width: double.infinity,
                  height: 60,
                  child: Material(
                    color: Colors.transparent,
                    child: InkWell(
                      borderRadius: BorderRadius.all(Radius.circular(10)),
                      onTap: () => _loadRewardAds(),
                      child: Ink(
                        child: Container(
                          decoration: BoxDecoration(
                            borderRadius:
                            BorderRadius.all(Radius.circular(10)),
                            color: Colors.black,
                          ),
                          alignment: Alignment.center,
                          child: Padding(
                            padding: EdgeInsets.symmetric(vertical: 16.0),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Text("Show Reward Ads",
                                    style: TextStyle(
                                        fontSize: 20,
                                        fontWeight: FontWeight.bold,
                                        color: Colors.white)),
                              ],
                            ),
                          ),
                        ),
                      ),
                    ),
                  )),
              SizedBox(height: 16.h),*/
              /*GoogleApplovinUnityAds.nativeAds(NativeSize.SMALL_NATIVE, Colors.transparent),
              SizedBox(height: 16.h),*/
              Container(height: 100, child: Container()),
            ],
          ),
        ) // This trailing comma makes auto-formatting nicer for build methods.
        );
  }
}

abstract class _OpenAdState<T extends StatefulWidget> extends State<T> with WidgetsBindingObserver {
  bool isAdShow = false;

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    if (state == AppLifecycleState.resumed) {
      print("CHECK On Resumed Called");
      if(!isAdShow)
        GoogleApplovinUnityAds.showOpenAds(callback: () => {
          isAdShow = true
        });
    }

    if (state == AppLifecycleState.paused) {
      print("CHECK On Paused Called");
      isAdShow = false;
    }
  }

  @override
  void dispose() {
    super.dispose();
    WidgetsBinding.instance.removeObserver(this);
  }

}
4
likes
0
pub points
34%
popularity

Publisher

unverified uploader

Ads Implement

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on google_applovin_unity_ads