[Native Ad] Ad is misplaced at the top of the screen on iOS
See original GitHub issuePlugin Version
google_mobile_ads: 0.12.1+1
Environment
Platform: iOS Flutter version: 2.0.5 SDK version: “>=2.12.0 ❤️.0.0”
Error description
The native ad widget is used in a SingleChildScrollView widget which scrolls horizontally. The native ad is loaded and displayed as aspected in the view but there is also an additional (unintentionally) ad that is placed at the top of the screen (see screenshot).
The app was recently migrated to null safety. This weird behavior occurred since the migration to null safety and update to Flutter 2.0. Before the migration the ad wasn’t placed at the top.
My code
class NativeAdWidget extends StatefulWidget {
static const String ADVERTISER_VIEW = "advertiser";
static const String BODY_VIEW = "body";
static const String ICON_VIEW = "icon";
static const String CTA_VIEW = "cta";
final Size? size;
final EdgeInsets? margin;
final List<String> visibleViews;
NativeAdWidget({this.size, this.margin, this.visibleViews = const []});
@override
_NativeAdWidgetState createState() => _NativeAdWidgetState();
}
class _NativeAdWidgetState extends State<NativeAdWidget> {
final String nativeAdFactory = "nativeAdFactory";
final String nativeAdUnitId = Platform.isAndroid
? "ca-app-pub-***"
: "ca-app-pub-***;
NativeAd? _nativeAd;
BehaviorSubject<bool> _adVisibilitySubject = BehaviorSubject.seeded(false);
@override
void didChangeDependencies() {
super.didChangeDependencies();
if (_nativeAd == null) {
if (AppConfig.googleAdsEnabled) {
Alerts.showiOSTrackingPermissionDialog(context).then((value) {
_nativeAd = _createNativeAd();
_nativeAd!.load();
});
}
}
}
@override
void dispose() {
_adVisibilitySubject.close();
if (AppConfig.googleAdsEnabled) _nativeAd?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return StreamBuilder<bool>(
stream: _adVisibilitySubject,
initialData: _adVisibilitySubject.value,
builder: (ctx, snapshot) {
if (AppConfig.googleAdsEnabled && snapshot.data!) {
return Container(
margin: widget.margin,
width: widget.size?.width,
height: widget.size?.height,
child: AdWidget(ad: _nativeAd!));
} else {
return Container();
}
});
}
NativeAd _createNativeAd() {
return NativeAd(
adUnitId: nativeAdUnitId,
factoryId: nativeAdFactory,
listener: _createAdListener(),
request: AdRequest(nonPersonalizedAds: false),
customOptions: {
"theme": DeviceConfig.appTheme.toString().split(".")[1],
"visibleViews": widget.visibleViews
});
}
AdListener _createAdListener() {
return AdListener(
onAdLoaded: (ad) => _adVisibilitySubject.add(true),
onAdFailedToLoad: (ad, error) {
_nativeAd?.dispose();
_nativeAd = null;
});
}
}
Screenshot
Logs
WF: _WebFilterIsActive returning: NO
WF: _userSettingsForUser mobile: {
filterBlacklist = (
);
filterWhitelist = (
);
restrictWeb = 1;
useContentFilter = 0;
useContentFilterOverrides = 0;
whitelistEnabled = 0;
}
WF: _WebFilterIsActive returning: NO
[assertion] Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=3 "Target is not running or required target entitlement is missing" UserInfo={RBSAssertionAttribute=<RBSDomainAttribute| domain:"com.apple.webkit" name:"Background" sourceEnvironment:"(null)">, NSLocalizedFailureReason=Target is not running or required target entitlement is missing}>
[ProcessSuspension] 0x1189ba2c0 - ProcessAssertion: Failed to acquire RBS Background assertion 'WebProcess Background Assertion' for process with PID 829, error: Error Domain=RBSAssertionErrorDomain Code=3 "Target is not running or required target entitlement is missing" UserInfo={RBSAssertionAttribute=<RBSDomainAttribute| domain:"com.apple.webkit" name:"Background" sourceEnvironment:"(null)">, NSLocalizedFailureReason=Target is not running or required target entitlement is missing}
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
Block pop-up ads and windows in Safari - Apple Support
Block pop-up ads and windows in Safari. Learn how to block pop-up windows and handle persistent ads on your iPhone, iPad, or Mac....
Read more >Google Advance Native Ad Display issue - ios - Stack Overflow
I am using google advance native Ad. My Ad is display successfully on simulator and device when I run from Xcode, but when...
Read more >Full-screen native ads | iOS - Google Developers
Full-screen native ads can improve revenue and retention, either through ... the AdChoices icon is placed at the top-right corner of the ad, ......
Read more >Guidelines for programmatic native ads using app code
This article describes the guidelines for programmatic native ads using the Android & iOS app code option. These guidelines do not apply to....
Read more >Native advertising: what's the fuss? - The Guardian
Frédéric Filloux: The row over brand content – also known as advertorials – is a festival of fake naïveté and misplaced indignation.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Probably related to https://github.com/googleads/googleads-mobile-flutter/issues/174
Duplicate of flutter/flutter#76097