Facing the issue during ads implementation, i have Initialized perfectly and implemented code as per documentation but still facing this issue, can any help me to resolve the issue?
Error:
> I --------------- IronSource --------------
> I >>>> IronSource - VERIFIED
> E No rewarded video configurations found
> E rewardedVideo ad unit has already been initialized
Code is:
import 'dart:developer';
import 'dart:io';
import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutterquiz/features/profileManagement/cubits/userDetailsCubit.dart';
import 'package:flutterquiz/features/systemConfig/cubits/systemConfigCubit.dart';
import 'package:flutterquiz/utils/constants/error_message_keys.dart';
import 'package:flutterquiz/utils/extensions.dart';
import 'package:flutterquiz/utils/ui_utils.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
import 'package:ironsource_mediation/ironsource_mediation.dart';
import 'package:unity_ads_plugin/unity_ads_plugin.dart';
abstract class RewardedAdState {}
class RewardedAdInitial extends RewardedAdState {}
class RewardedAdLoaded extends RewardedAdState {}
class RewardedAdLoadInProgress extends RewardedAdState {}
class RewardedAdFailure extends RewardedAdState {}
class RewardedAdCubit extends Cubit<RewardedAdState> {
RewardedAdCubit() : super(RewardedAdInitial()) {
_initializeIronSource();
}
RewardedAd? _rewardedAd;
RewardedAd? get rewardedAd => _rewardedAd;
void _initializeIronSource() {
IronSource.init(appKey: '20xxxxxxx', adUnits: [IronSourceAdUnit.RewardedVideo]);
IronSource.validateIntegration();
IronSource.shouldTrackNetworkState(true);
IronSource.setAdaptersDebug(true);
IronSource.setConsent(true);
IronSource.setLevelPlayRewardedVideoManualListener(_IronSourceRewardedVideoListener(this));
}
void _createIronSourceRewardedAd() {
emit(RewardedAdLoadInProgress());
IronSource.loadRewardedVideo();
}
void createUnityRewardsAd() {
UnityAds.load(
placementId: unityRewardsPlacement(),
onComplete: (placementId) => emit(RewardedAdLoaded()),
onFailed: (p, e, m) => emit(RewardedAdFailure()),
);
}
void createRewardedAd(BuildContext context) {
emit(RewardedAdLoadInProgress());
final sysConfigCubit = context.read<SystemConfigCubit>();
if (sysConfigCubit.isAdsEnable && !context.read<UserDetailsCubit>().removeAds()) {
if (sysConfigCubit.adsType == 1) {
_createIronSourceRewardedAd();
} else {
createUnityRewardsAd();
}
}
}
Future<void> showDailyAd({required BuildContext context}) async {
final sysConfigCubit = context.read<SystemConfigCubit>();
final userDetails = context.read<UserDetailsCubit>();
if (sysConfigCubit.isAdsEnable && state is RewardedAdLoaded) {
if (sysConfigCubit.adsType == 1) {
await IronSource.showRewardedVideo();
} else {
await UnityAds.showVideoAd(
placementId: unityRewardsPlacement(),
onComplete: (_) async {
await userDetails.watchedDailyAd().then((_) async {
await context.read<UserDetailsCubit>().fetchUserDetails();
if (!context.mounted) return;
UiUtils.showSnackBar(
"${context.tr("earnedLbl")!} ${sysConfigCubit.coinsPerDailyAdView} ${context.tr("coinsLbl")!}",
context,
duration: const Duration(seconds: 2),
);
}).catchError((dynamic e) {
if (e.toString() == errorCodeDailyAdsLimitSucceeded) {
UiUtils.showSnackBar(
context.tr('dailyAdsLimitExceeded')!,
context,
);
}
});
},
);
}
} else if (state is RewardedAdFailure) {
createRewardedAd(context);
}
}
void showAd({
required VoidCallback onAdDismissedCallback,
required BuildContext context,
}) {
final sysConfigCubit = context.read<SystemConfigCubit>();
if (sysConfigCubit.isAdsEnable && !context.read<UserDetailsCubit>().removeAds()) {
if (state is RewardedAdLoaded) {
if (sysConfigCubit.adsType == 1) {
IronSource.showRewardedVideo();
onAdDismissedCallback();
_createIronSourceRewardedAd();
} else {
UnityAds.showVideoAd(
placementId: unityRewardsPlacement(),
onComplete: (placementId) {
onAdDismissedCallback();
createRewardedAd(context);
},
);
}
} else if (state is RewardedAdFailure) {
createRewardedAd(context);
}
}
}
String unityRewardsPlacement() {
if (Platform.isAndroid) {
return 'Rewarded_Android';
}
if (Platform.isIOS) {
return 'Rewarded_iOS';
}
return '';
}
}
class _IronSourceRewardedVideoListener implements LevelPlayRewardedVideoManualListener {
final RewardedAdCubit cubit;
_IronSourceRewardedVideoListener(this.cubit);
@override
void onAdClicked(IronSourceRewardedVideoPlacement placement, IronSourceAdInfo adInfo) {
// Handle ad click
}
void onAdAvailable(IronSourceAdInfo adInfo) {
log('IronSource Rewarded Ad Loaded');
cubit.emit(RewardedAdLoaded());
}
@override
void onAdClosed(IronSourceAdInfo adInfo) {
log('IronSource Rewarded Ad Closed');
cubit.emit(RewardedAdInitial());
cubit._createIronSourceRewardedAd();
}
@override
void onAdOpened(IronSourceAdInfo adInfo) {
// Handle ad opened
}
@override
void onAdRewarded(IronSourceRewardedVideoPlacement placement, IronSourceAdInfo adInfo) {
// Handle ad rewarded
}
@override
void onAdShowFailed(IronSourceError error, IronSourceAdInfo adInfo) {
log('IronSource Ad Show Failed: $error');
cubit.emit(RewardedAdFailure());
}
@override
void onAdUnavailable() {
log('IronSource Rewarded Ad Not Available');
cubit.emit(RewardedAdFailure());
}
@override
void onAdLoadFailed(IronSourceError error) {
log('IronSource Ad Load Failed: $error');
cubit.emit(RewardedAdFailure());
}
@override
void onAdReady(IronSourceAdInfo adInfo) {
log('IronSource Ad Ready');
}
}
How to solve this issue?