google_applovin_unity_ads 2.3.28 google_applovin_unity_ads: ^2.3.28 copied to clipboard
Ads Implement
example/lib/main.dart
// Copyright 2022 Bitcoding
import 'dart:convert';
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/custom_dialog.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';
Widget _nativeAd = Container(height: 0);
Widget _nativeAd2 = Container(height: 0);
Widget _nativeAd4 = Container(height: 0);
Widget _bannerAd = Container(height: 0);
@override
void initState() {
super.initState();
Future.delayed(
const Duration(seconds: 1),
() => {
fetchAdsSettings(
appVersionCode: 1,
settingsUrl:
"https://gitlab.com/prbitcoding/ads_setting/-/raw/main/ads.json",
keyName: "com.bitlinks.pakistan.iptv.m3ulist")
.then((value) => {
if ((getAdsSettings()?.appLovin?.sdkKey ?? "").isNotEmpty) {
AppLovinAds.instance
.initialize(
getAdsSettings()?.appLovin?.sdkKey ?? ""
).then((value) => {
loadIntraAds(),
loadRewardAds(),
showNativeAds(
onAdLoadedCallback: (p0) {
setState(() {
_nativeAd = p0;
});
},
),
showBannerAds(
size: AdSize.mediumRectangle,
onAdLoadedCallback: (p0) {
setState(() {
_bannerAd = p0;
});
},
),
})
},
})
});
}
@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("as dasd asd asd asd asd Old Show Completed true")});
break;
case 'RewardedAd':
showRewardAds(
callback: () => {print("Show Completed true")},
onSkippedCallback: () => {print("Skipped Ad true")},
onFailedCallback: () => {
showIntraAds(
isCompulsory: true,
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: SingleChildScrollView(
child: Column(children: [
_nativeAd,
SizedBox(height: 20),
Text(placeholderText),
SizedBox(height: 20),
_nativeAd2,
SizedBox(height: 20),
TextButton(
style: ButtonStyle(
overlayColor: MaterialStateProperty.resolveWith<Color?>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.focused))
return Colors.red;
return null; // Defer to the widget's default.
}),
),
onPressed: () {
showIntraAds(callback: () {});
},
child: const Text('INTRA ADS'),
),
SizedBox(height: 20),
TextButton(
style: ButtonStyle(
overlayColor: MaterialStateProperty.resolveWith<Color?>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.focused))
return Colors.red;
return null; // Defer to the widget's default.
}),
),
onPressed: () {
showRewardAds(callback: () {});
},
child: const Text('REWARD ADS'),
),
SizedBox(height: 20),
_nativeAd4,
]),
),
),
bottomNavigationBar: _bannerAd,
);
}),
);
}
}