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

outdated

Ads Implement

example/lib/main.dart

// Copyright 2022 Bitcoding

import 'package:flutter/material.dart';
import 'package:get/route_manager.dart';
import 'package:google_applovin_unity_ads/google_applovin_unity_ads.dart';
import 'package:google_applovin_unity_ads_example/main_screen.dart';

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

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

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  final String placeholderText =
      'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod'
      ' tempor incididunt ut labore et dolore magna aliqua. Faucibus purus in'
      ' massa tempor. Quis enim lobortis scelerisque fermentum dui faucibus'
      ' in. Nibh praesent tristique magna sit amet purus gravida quis.'
      ' Magna sit amet purus gravida quis blandit turpis cursus in. Sed'
      ' adipiscing diam donec adipiscing tristique. Urna porttitor rhoncus'
      ' dolor purus non enim praesent. Pellentesque habitant morbi tristique'
      ' senectus et netus. Risus ultricies tristique nulla aliquet enim tortor'
      ' at.';

  Widget _nativeAd = Container(height: 0);

  @override
  void initState() {
    super.initState();
    Future.delayed(
        const Duration(seconds: 1),
        () => {
              fetchAdsSettings(
                      appVersionCode: 1,
                      settingsUrl:
                          "https://gitlab.com/pp.bitcoding/demotest/-/raw/main/test.json",
                      keyName: "com.bitlinks.arebic.iptv.m3ulist")
                  .then((value) => {
                        if ((getAdsSettings()?.appLovin?.sdkKey ?? "")
                            .isNotEmpty)
                          {
                            AppLovinAds.instance
                                .initialize(getAdsSettings()!.appLovin!.sdkKey!)
                                .then((value) => {
                                      // initOpenAds(onOpenAdLoaded: () => {showOpenAds()}),
                                      // loadIntraAds(),
                                      loadRewardAds(),
                                      /* loadNativeAds(
                                onAdLoadedCallback: () => {
                                  setState(() {
                                    _nativeAd = showNativeAds();
                                  })
                                }),*/
                                    })
                          },
                      })
            });
  }

  @override
  void dispose() {
    super.dispose();
    destroyAd();
  }

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      home: Builder(builder: (BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: const Text('Ads example app'),
            actions: <Widget>[
              PopupMenuButton<String>(
                onSelected: (String result) {
                  switch (result) {
                    case 'InterstitialAd':
                      showIntraAds(
                          callback: () => {print("Show Completed true")});
                      break;
                    case 'RewardedAd':
                      showRewardAds(
                          callback: () => {print("Show Completed true")},
                          onFailedCallback: () => {
                                showIntraAds(
                                    callback: () =>
                                        {print("Show Completed true")})
                              });
                      break;
                    case 'MainScreen':
                      Navigator.push(context, MaterialPageRoute(
                        builder: (context) {
                          return const MainScreen();
                        },
                      ));
                      break;
                    default:
                      throw AssertionError('unexpected button: $result');
                  }
                },
                itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
                  const PopupMenuItem<String>(
                    value: 'InterstitialAd',
                    child: Text('InterstitialAd'),
                  ),
                  const PopupMenuItem<String>(
                    value: 'RewardedAd',
                    child: Text('RewardedAd'),
                  ),
                  const PopupMenuItem<String>(
                    value: 'MainScreen',
                    child: Text('MainScreen'),
                  )
                ],
              ),
            ],
          ),
          body: SafeArea(
            child: Text(placeholderText),
          ),
          bottomNavigationBar: _nativeAd,
        );
      }),
    );
  }
}
4
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Ads Implement

License

unknown (license)

Dependencies

flutter, get, http, meta, visibility_detector

More

Packages that depend on google_applovin_unity_ads