elCaribe app - customization and branding
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:google_mobile_ads/google_mobile_ads.dart';
|
||||
import 'package:news/cubits/appSystemSettingCubit.dart';
|
||||
|
||||
const AdRequest request = AdRequest(
|
||||
//static
|
||||
keywords: <String>['foo', 'bar'],
|
||||
contentUrl: 'http://foo.com/bar.html',
|
||||
nonPersonalizedAds: true,
|
||||
);
|
||||
RewardedAd? rewardedAd;
|
||||
int _numRewardedLoadAttempts = 0;
|
||||
int maxFailedLoadAttempts = 3;
|
||||
|
||||
void createGoogleRewardedAd(BuildContext context) {
|
||||
if (context.read<AppConfigurationCubit>().rewardId() != "") {
|
||||
RewardedAd.load(
|
||||
adUnitId: context.read<AppConfigurationCubit>().rewardId()!,
|
||||
request: request,
|
||||
rewardedAdLoadCallback: RewardedAdLoadCallback(
|
||||
onAdLoaded: (RewardedAd ad) {
|
||||
rewardedAd = ad;
|
||||
_numRewardedLoadAttempts = 0;
|
||||
},
|
||||
onAdFailedToLoad: (LoadAdError error) {
|
||||
rewardedAd = null;
|
||||
_numRewardedLoadAttempts += 1;
|
||||
if (_numRewardedLoadAttempts <= maxFailedLoadAttempts) {
|
||||
createGoogleRewardedAd(context);
|
||||
}
|
||||
},
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
void showGoogleRewardedAd(BuildContext context) {
|
||||
if (context.read<AppConfigurationCubit>().rewardId() != "") {
|
||||
if (rewardedAd == null) {
|
||||
return;
|
||||
}
|
||||
rewardedAd!.fullScreenContentCallback = FullScreenContentCallback(
|
||||
onAdShowedFullScreenContent: (RewardedAd ad) => debugPrint('ad onAdShowedFullScreenContent.'),
|
||||
onAdDismissedFullScreenContent: (RewardedAd ad) {
|
||||
ad.dispose();
|
||||
createGoogleRewardedAd(context);
|
||||
},
|
||||
onAdFailedToShowFullScreenContent: (RewardedAd ad, AdError error) {
|
||||
ad.dispose();
|
||||
createGoogleRewardedAd(context);
|
||||
},
|
||||
);
|
||||
|
||||
rewardedAd!.setImmersiveMode(true);
|
||||
rewardedAd!.show(onUserEarnedReward: (AdWithoutView ad, RewardItem reward) {});
|
||||
rewardedAd = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:unity_ads_plugin/unity_ads_plugin.dart';
|
||||
|
||||
void loadUnityRewardAd(String placementId) {
|
||||
UnityAds.load(placementId: placementId, onComplete: (placementId) {}, onFailed: (placementId, error, message) {});
|
||||
}
|
||||
|
||||
void showUnityRewardAds(String placementId) {
|
||||
UnityAds.showVideoAd(
|
||||
placementId: placementId,
|
||||
onComplete: (placementId) {
|
||||
loadUnityRewardAd(placementId);
|
||||
},
|
||||
onFailed: (placementId, error, message) {
|
||||
loadUnityRewardAd(placementId);
|
||||
},
|
||||
onStart: (placementId) => debugPrint('Video Ad $placementId started'),
|
||||
onClick: (placementId) => debugPrint('Video Ad $placementId click'),
|
||||
onSkipped: (placementId) {
|
||||
loadUnityRewardAd(placementId);
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user