google_applovin_unity_ads 1.0.8 google_applovin_unity_ads: ^1.0.8 copied to clipboard
Ads Implement
Add the dependency in pubspec.yaml
:
PERSONAL PACKAGE #
dependencies:
... google_applovin_unity_ads: ^1.0.7
ADD ANDROID MANIFEST #
//PERMISSION
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
//META DATA
<applicaton
...
android:usesCleartextTraffic="true">
<meta-data
android:name="applovin.sdk.key"
android:value="ENTER APPLOVING SDK KEY" />
<meta-data
android:name="applovin.sdk.verbose_logging"
android:value="true" />
<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>
BUILD GRADLE #
multiDexEnabled true
targetSdkVersion 33
ADD MAIN.DART #
WidgetsFlutterBinding.ensureInitialized();
await APICALLINGMETHOD();
if ((apiModel?.comIptvM3UPlaylists ?? "").toString().isNotEmpty) {
GoogleApplovinUnityAds.initialize(
jsonEncode(apiModel?.comIptvM3UPlaylists).toString(),
callback: () => {runApp(const IPTV())});
}
ADD VERSION CODE FUNCTION
dependencies:
package_info_plus:
int versionCode = 1;
PackageInfo packageInfo = await PackageInfo.fromPlatform();
setState(() {
versionCode = int.parse(packageInfo.buildNumber);
print("11111111- ${versionCode}");
});
ADS_FILE.DART #
import 'package:flutter/material.dart';
import 'package:google_applovin_unity_ads/google_applovin_unity_ads.dart';
import 'package:google_applovin_unity_ads/native/controller.dart';
import 'package:sizer/sizer.dart';
import '../main.dart';
showIntraAds({Function? callback}) async {
ControllerGetX.to.isAdShow.value=true;
if (modelApi!.comBitlinksEnglishIptvM3ulist!.adSetting!.appVersionCode == ControllerGetX.to.versionCode.value) {
if (callback != null) {
callback();
}
} else {
GoogleApplovinUnityAds.showIntraAds(callback: callback);
}
}
Future<void> showRewardAds({Function? callback}) async {
ControllerGetX.to.isAdShow.value=true;
if (modelApi!.comBitlinksEnglishIptvM3ulist!.adSetting!.appVersionCode == ControllerGetX.to.versionCode.value) {
if (callback != null) {
callback();
}
} else {
GoogleApplovinUnityAds.showRewardAds(callback: callback);
}
}
bannerAds() {
if (modelApi!.comBitlinksEnglishIptvM3ulist!.adSetting!.appVersionCode == ControllerGetX.to.versionCode.value ||
modelApi!.comBitlinksEnglishIptvM3ulist!.adsSequence!.isEmpty) {
return Container(
height: 0,
);
}
return GoogleApplovinUnityAds.bannerAds();
}
fullNativeAds() {
if (modelApi!.comBitlinksEnglishIptvM3ulist!.adSetting!.appVersionCode == ControllerGetX.to.versionCode.value ||
modelApi!.comBitlinksEnglishIptvM3ulist!.adsSequence!.isEmpty ||
(modelApi!.comBitlinksEnglishIptvM3ulist!.adsSequence!.length == 1 &&
modelApi!.comBitlinksEnglishIptvM3ulist!.adsSequence![0] == "custom_ads")) {
return Container(
height: 0,
);
}
return GoogleApplovinUnityAds.nativeAds(
NativeSize(Size(double.infinity, 50.h)), "F",
error: Container(
height: 0,
));
}
mediumNativeAds() {
if (modelApi!.comBitlinksEnglishIptvM3ulist!.adSetting!.appVersionCode == ControllerGetX.to.versionCode.value ||
modelApi!.comBitlinksEnglishIptvM3ulist!.adsSequence!.isEmpty ||
(modelApi!.comBitlinksEnglishIptvM3ulist!.adsSequence!.length == 1 &&
modelApi!.comBitlinksEnglishIptvM3ulist!.adsSequence![0] == "custom_ads")) {
return Container(
height: 0,
);
}
return GoogleApplovinUnityAds.nativeAds(
NativeSize(Size(double.infinity, 150.h)), "M");
}
showOpenAd() {
if (modelApi!.comBitlinksEnglishIptvM3ulist!.adSetting!.appVersionCode == ControllerGetX.to.versionCode.value ||
modelApi!.comBitlinksEnglishIptvM3ulist!.adsSequence!.isEmpty) {
return;
}
GoogleApplovinUnityAds.showOpenAds();
}
smallNativeAds() {
if (modelApi!.comBitlinksEnglishIptvM3ulist!.adSetting!.appVersionCode == ControllerGetX.to.versionCode.value ||
modelApi!.comBitlinksEnglishIptvM3ulist!.adsSequence!.isEmpty ||
(modelApi!.comBitlinksEnglishIptvM3ulist!.adsSequence!.length == 1 &&
modelApi!.comBitlinksEnglishIptvM3ulist!.adsSequence![0] == "custom_ads")) {
return Container(
height: 0,
);
}
return GoogleApplovinUnityAds.nativeAds(
NativeSize(Size(double.infinity, 50.h)), "S");
}
isFullAdss(){
modelApi!.comBitlinksEnglishIptvM3ulist!.adSetting!.isFullAds==true?
showIntraAds():Container();
}
isFullAdssNative(){
return modelApi!.comBitlinksEnglishIptvM3ulist!.adSetting!.isFullAds==true?
mediumNativeAds():Container();
}
OPEN ADS #
// abstract class for Open Ad
// Normal statefullwidget
abstract class OpenAdState<T extends StatefulWidget> extends State<T> with WidgetsBindingObserver {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
print('setp 1==================$state');
if (state == AppLifecycleState.resumed) {
print('setp 2==================Resume${ControllerGetX.to.isAdShow.value}');
if(!ControllerGetX.to.isAdShow.value) {
print('setp 3==================');
ControllerGetX.to.isAdShow.value = true;
GoogleApplovinUnityAds.showOpenAds();
}
}
if (state == AppLifecycleState.paused) {
ControllerGetX.to.isAdShow.value = false;
}
}
@override
void dispose() {
super.dispose();
WidgetsBinding.instance.removeObserver(this);
}
}
// When GetX will be used
abstract class OpenAdState<T extends GetxController> extends GetView<T>
with WidgetsBindingObserver {
OpenAdState({Key? key}) : super(key: key) {
WidgetsBinding.instance.addPostFrameCallback((_) => initialization());
}
Future<void> initialization({BuildContext? context}) async {
WidgetsBinding.instance.addObserver(this);
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
print("Yes yes Open Adddddddsss $state");
if (state == AppLifecycleState.resumed) {
print("Yes yes Open Adddddddsss $state 121212");
if (!WelcomeController.to.isAdShow.value) {
print("Yes yes Open Adddddddsss $state 2323232323");
WelcomeController.to.isAdShow.value = true;
GoogleApplovinUnityAds.showOpenAds();
}
}
if (state == AppLifecycleState.paused) {
print("Yes yes Open Adddddddsss $state 4545454545454");
WelcomeController.to.isAdShow.value = false;
}
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
}
}
APPLOVIN SDK KEY SETTING #
"app_lovin": {
"sdk_key": "l2eT38yPMONBdyKO3A",
"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
}17
or
```xml
<applicaton ......... >
<meta-data android:name="applovin.sdk.key" android:value="l2eT38yPMONBdyKO3A" />
<meta-data android:name="applovin.sdk.verbose_logging" android:value="true" />
</application>