google_applovin_unity_ads 2.2.1 google_applovin_unity_ads: ^2.2.1 copied to clipboard
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();
FacebookAds.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/piyushTest.json",
keyName: "com.bitlinks.pakistan.iptv.m3ulist")
.then((value) => {
if ((getAdsSettings()?.appLovin?.sdkKey ?? "")
.isNotEmpty)
{
AppLovinAds.instance
.initialize(getAdsSettings()!.appLovin!.sdkKey!)
.then((value) => {
loadRewardAds(),
showBannerAds(
onAdLoadedCallback: (nativeAd) => {
setState(() {
_nativeAd = nativeAd;
})
}),
})
},
})
});
}
@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 onFailedCallback")
})
});
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,
);
}),
);
}
}