Closed athlona64 closed 4 years ago
"it not available to load" - Would you provide the 'error message' or log files please.
it's show "An ad has loaded successfully in memory." in round two but can't open video ads
I'm not experiencing such an issue. Have you been able to get the example code to work? What tool are you using: Android Studio? Do you see anything in the Logcat?
Is this still an issue?
I had a similar issue. It appears to happen when the Ads Widget provided by the library unloads once. (I encountered this when I used Navigator.push() or Navigator.pop() and come to revisit the page the ad does not load).
Moving it to a static class and having the Ads instance static works. The below code is a working solution using static instantiated Ad
import 'package:flutter/material.dart';
import 'dart:io' show Platform;
import 'package:firebase_admob/firebase_admob.dart';
import 'package:ads/ads.dart';
class AdProvider {
static final String _appId = Platform.isAndroid
? ''
: '';
static final String _videoUnitId = Platform.isAndroid
? ''
: '';
static final String _bannerUnitId = Platform.isAndroid
? ''
: '';
static Ads _ads = Ads(_appId);
/// Assign a listener.
static MobileAdListener _eventListener = (MobileAdEvent event) {
if (event == MobileAdEvent.clicked) {
print("_eventListener: The opened ad is clicked on.");
}
};
static void showBanner(
{String adUnitId,
AdSize size,
List<String> keywords,
String contentUrl,
bool childDirected,
List<String> testDevices,
bool testing,
MobileAdListener listener,
State state,
double anchorOffset,
AnchorType anchorType}) =>
_ads?.showBannerAd(
adUnitId: adUnitId,
size: size,
keywords: keywords,
contentUrl: contentUrl,
childDirected: childDirected,
testDevices: testDevices,
testing: testing,
listener: listener,
state: state,
anchorOffset: anchorOffset,
anchorType: anchorType);
static void hideBanner() => _ads?.closeBannerAd();
/// Call this static function in your State object's initState() function.
static void init() => _ads ??= Ads(
_appId,
bannerUnitId: _bannerUnitId,
keywords: <String>['ibm', 'computers'],
contentUrl: 'http://www.ibm.com',
childDirected: false,
testDevices: ['Samsung_Galaxy_SII_API_26:5554'],
testing: false,
listener: _eventListener,
);
/// Remember to call this in the State object's dispose() function.
static void dispose() => _ads?.dispose();
static showAd(eventListener) async {
_ads.setVideoAd(
adUnitId: _videoUnitId,
keywords: ['fitness', 'supplements', 'diet', 'weight loss'],
contentUrl: 'http://www.publang.org',
childDirected: true,
listener: eventListener
);
_ads.showVideoAd();
_ads.dispose();
}
}
and invoke like so:
AdProvider.showAd((RewardedVideoAdEvent event, {String rewardType, int rewardAmount}) {
setState(() {
adSeen = true;
});
});
Interesting. Merely placing the class in a static reference allows it to display a video a follow-up time?? You're providing the Single Solution approach to the code. Note, I'm not getting this problem in the first place, but I'll see what I can do to re-create the issue.
first ads is show normally but when end ads and get rewards i'm click round two it not available to load ads
but i close app and open again it can watch