We have created the following class to display AdMob on flutter.
import 'package:firebase_admob/firebase_admob.dart';
import 'package:xxxxx/models/const.dart';
class Ads {
static BannerAd _bannerAd;
static init() {
FirebaseAdMob.instance.initialize(appId: Const.adAppId);
}
static BannerAd createBannerAd() {
return new BannerAd(
adUnitId: Const.adUnitId,
size: AdSize.banner,
targetingInfo: targetingInfo,
listener: (MobileAdEvent event) {
print("@@@ $event @@@");
},
);
}
static void showBanner() {
if (_bannerAd == null) {
_bannerAd = createBannerAd();
}
print('@@@ load @@@');
_bannerAd.load().then((load) {
print('@@@ show @@@');
_bannerAd.show(anchorType: AnchorType.bottom);
});
}
static void hideBanner() {
print('@@@ dispose @@@');
_bannerAd?.dispose();
print('@@@ null @@@');
_bannerAd = null;
}
static final MobileAdTargetingInfo targetingInfo = new MobileAdTargetingInfo(
testDevices: Const.testDevices,
keywords: Const.keywords,
birthday: new DateTime.now(),
gender: MobileAdGender.female,
);
}
The following values are correctly defined in the Const class.
adAppId, adUnitId, testDevices, keywords
init() is called immediately after startup.
showBanner() will be called when showing the ad.
hideBanner() will be called when hiding the ad.
These will work as expected in most cases.
But after _bannerAd.show() is called, the ad will not be hidden if hideBanner() is called before the listener receives MobileAdEvent.loaded.
[OK]
_bannerAd.show() -> receive MobileAdEvent.loaded -> hideBanner()
flutter: @@@ load @@@
flutter: @@@ show @@@
flutter: @@@ MobileAdEvent.loaded @@@
flutter: @@@ dispose @@@
flutter: @@@ null @@@
[NG]
_bannerAd.show() -> hideBanner() -> (receive MobileAdEvent.loaded)
flutter: @@@ load @@@
flutter: @@@ show @@@
flutter: @@@ dispose @@@
flutter: @@@ null @@@
This trouble occurred in ASUS Z017DA. iPad mini, iPhone 6 Plus and iPhone 4S were hidden normally at any timing. We can not test all models, but it may be a problem only for Android.
How can we avoid this if we do?
$ flutter doctor -v
[β] Flutter (Channel dev, v0.7.5, on Mac OS X 10.13.6 17G65, locale ja)
β’ Flutter version 0.7.5 at /Applications/flutter
β’ Framework revision eab5cd9853 (6 days ago), 2018-08-30 14:47:04 -0700
β’ Engine revision dc7b5eb89d
β’ Dart version 2.1.0-dev.3.0.flutter-760a9690c2
[β] Android toolchain - develop for Android devices (Android SDK 27.0.3)
β’ Android SDK at /Users/xxxxx/src/android-sdks
β’ Android NDK at /Users/xxxxx/src/android-sdks/ndk-bundle
β’ Platform android-27, build-tools 27.0.3
β’ ANDROID_HOME = /Users/xxxxx/src/android-sdks
β’ Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
β’ Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
β’ All Android licenses accepted.
[β] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
β’ Xcode at /Applications/Xcode.app/Contents/Developer
β’ Xcode 9.4.1, Build version 9F2000
β’ ios-deploy 1.9.2
β’ CocoaPods version 1.5.3
[β] Android Studio (version 3.1)
β’ Android Studio at /Applications/Android Studio.app/Contents
β’ Flutter plugin version 27.1.1
β’ Dart plugin version 173.4700
β’ Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
[β] VS Code (version 1.25.1)
β’ VS Code at /Applications/Visual Studio Code.app/Contents
β’ Flutter extension version 2.18.0
[β] Connected devices (2 available)
β’ ASUS Z017DA β’ XXXXXXXXXXXXXXX β’ android-arm64 β’ Android 8.0.0 (API 26)
β’ iPhone 6 Plus β’ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx β’ ios β’ iOS 11.4.1
β’ No issues found!
@ganessaa
The issue at https://github.com/flutter/flutter/issues/21474 has been closed and moved here. Future collaboration on this issue will be done here.
This issue is a blocker for my app. I cannot hide the ad when the users choose to hide the ad by paying. Currently, I have to stop using Admob at all. This could be a very urgent requirement as there are many app developers who are using this like me.
This issue is a blocker for my app. I cannot hide the ad when the users choose to hide the ad by paying. Currently, I have to stop using Admob at all. This could be a very urgent requirement as there are many app developers who are using this like me.
Same scenario here (and after 4 months). I need to force the user to restart the app
Only solution is using another Admob package?
Only solution is using another Admob package?
for me honestly it was. Also the official one doesn't support native ads
Thanks
κΉμμΉ
- μ€ν 6:52, Daniel notifications@github.com μμ±:
ο»Ώ
Only solution is using another Admob package?for me honestly it was. Also the official one doesn't support native ads
β
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
any updates?
I have several ad units and different screen. When I am toggle/swipe between screens too "fast", the IOS able to close and open new ad perfectly fine however Android unable to dispose and close the old ad. Is there issues with Android OS?
Is there any update about this one ? This issue has been reported on the flutter repo since september 2018.
Tossing my work around here in case it helps anyone. Basically, only show the banner ad AFTER you receive the MobileAdEvent.loaded().
_bannerAd = createBannerAd()..load();
```
BannerAd createBannerAd() {
return BannerAd(
adUnitId: getAdUnitId(),
size: AdSize.banner,
targetingInfo: targetingInfo,
listener: (MobileAdEvent event) async {
if (event == MobileAdEvent.loaded) {
if (mounted) {
showBannerAd();
}
}
},
);
}
## Show the ad:
showBannerAd() {
_bannerAd.show(
anchorType: AnchorType.bottom,
);
}
```
Most helpful comment
This issue is a blocker for my app. I cannot hide the ad when the users choose to hide the ad by paying. Currently, I have to stop using Admob at all. This could be a very urgent requirement as there are many app developers who are using this like me.