
Step 1 : Add Google Mobile Ads Dependency In Pubspec.yaml (Always Check Latest Version)
google_mobile_ads: ^1.2.0"
Step 2 : Import Package In Your Class
“import 'package:google_mobile_ads/google_mobile_ads.dart';”
Step 3 : Inside Main.dart in mainMethod Initialize MobileAds
MobileAds.instance.initialize();
Step 4 : Create New Class For Advertisement Keys
import 'dart:io';
class AdManager {
static String get appId {
if (Platform.isAndroid) {
return "ca-app-pub-2603941825604734~6992079295";
} else {
throw new UnsupportedError("Unsupported platform");
}
}
static String get bannerAdUnitId {
if (Platform.isAndroid) {
return "ca-app-pub-3940256099942544/6300978111";
} else if (Platform.isIOS) {
return "ca-app-pub-3940256099942544/2934735716";
} else {
throw new UnsupportedError("Unsupported platform");
}
}
static String get interstitialAdUnitId {
if (Platform.isAndroid) {
return "ca-app-pub-3940256099942544/1033173712";
} else if (Platform.isIOS) {
return "ca-app-pub-3940256099942544/4411468910";
} else {
throw new UnsupportedError("Unsupported platform");
}
}
/// This Is Sample
// static String get rewardedAdUnitId {
// if (Platform.isAndroid) {
// return "";
// } else if (Platform.isIOS) {
// return "";
// } else {
// throw new UnsupportedError("Unsupported platform");
// }
// }
}
Step 5 : Make This Variable Global
InterstitialAd interstitialAd;
Step 6 : Create Constant Class For Banner Ads and Interstitial Ads
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
import 'admobid.dart';
class admobads {
Widget bannerads() {
final googleBannerAd = BannerAd(
adUnitId: AdManager.bannerAdUnitId,
size: AdSize.banner,
listener: const BannerAdListener(),
request: AdRequest(),
)..load();
return Container(
color: Colors.black12,
alignment: Alignment.bottomCenter,
width: googleBannerAd.size.width.toDouble(),
height: googleBannerAd.size.height.toDouble(),
child: AdWidget(ad: googleBannerAd),
);
}
/// Interstitial Ads
int maxFailedLoadAttempts = 3;
static final AdRequest request = AdRequest(
keywords: ['foo', 'bar'],
contentUrl: 'http://foo.com/bar.html',
nonPersonalizedAds: true,
);
InterstitialAd createInterstitialAd() {
InterstitialAd.load(
adUnitId:AdManager.interstitialAdUnitId,
request: request,
adLoadCallback: InterstitialAdLoadCallback(
onAdLoaded: (InterstitialAd ad) {
interstitialAd = ad;
// _interstitialAd = ad;
},
onAdFailedToLoad: (LoadAdError error) {
},
));
}
/// Over Interstitial Ads
/// Show IntertitialAd
void showInterstitialAd() {
if (interstitialAd == null) {
print('Warning: attempt to show interstitial before loaded.');
return;
}
interstitialAd.fullScreenContentCallback = FullScreenContentCallback(
onAdShowedFullScreenContent: (InterstitialAd ad) =>
print('ad onAdShowedFullScreenContent.'),
onAdDismissedFullScreenContent: (InterstitialAd ad) {
print('$ad onAdDismissedFullScreenContent.');
ad.dispose();
createInterstitialAd();
},
onAdFailedToShowFullScreenContent: (InterstitialAd ad, AdError error) {
print('$ad onAdFailedToShowFullScreenContent: $error');
ad.dispose();
createInterstitialAd();
},
);
interstitialAd.show();
interstitialAd = null;
}
}
Step 7 : For Call Banner Ads Any Where Simply Call This Function
Container(
width: MediaQuery.of(context).size.width,
color: Colors.black12,
child: admobads().bannerads(),
),
Step 8 : For IntertitoalAds You Should Once Call This Function When Application Start
admobads().createInterstitialAd();
Step 9 : For Interstitial Ads Paste This InSide OnTap
admobads().showInterstitialAd();
ParseObject playerObject = ParseObject("User_Post");
QueryBuilder lotsOfWins = QueryBuilder(
playerObject)
..includeObject(['Profile_Id'])
..whereEqualTo(
'Profile_Id', (ProfilePage()..objectId = "RjDUL5Dykn").toPointer());
var apiResponse = await lotsOfWins.query();
for (var i = 0; i < apiResponse.results!.length; i++) {
print(
"kkkk$i ${apiResponse.results![i].get('Profile_Id').get('Description')}");
}
© 2021. All rights reserved by creative digi tips.
Cookie | Duration | Description |
---|---|---|
cookielawinfo-checkbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
cookielawinfo-checkbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
cookielawinfo-checkbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |