-
Notifications
You must be signed in to change notification settings - Fork 287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getCurrentOrientationInlineAdaptiveBannerAdSize does not load inline ads #888
Comments
Hi @lukeirvin |
Hi @huycozy Thank you so much for your reply. Yes, I have tried this multiple times before, and trying again now. I still get an error when trying to display inline adaptive ads. Same error as what I shared above. The online time I can get this to go away is if I either hardcode a height/width value OR if I set the size to be something like AdSize.mediumRectangle vs. calculating the width & height. Update: I have banner ads as well & those load without any issues. Update 2: From Then within Then within my method of returning the Is it possible it is failing because the _bannerAd!.sizes.first.height is 0? |
I see this now. But even so, the ad still displays. Does it display on your device? Also, looks like googleads-mobile-flutter/packages/google_mobile_ads/lib/src/ad_containers.dart Lines 962 to 968 in 7599cba
|
Correct, I need to make inline adaptive ads & per the documentation, I would need to use No, the ad does NOT display for me. Just an empty space. |
Strange, I always see the ads. I see you are using an old plugin version |
I'll try to update the plugin. I know it will fail initially as I'll have to update some of the other packages as well to support it. I have followed the example code exactly as it is & it never works for me. Also to note, the only difference between the example & what I am doing is the example shows the ad at one index location. I'll need to show it at multiple indexes within a ListView. |
Thanks for your response. The context is more clear now. It seems there is an issue with the AdWidget loading mechanism in your ListView. In ListView, you should create isolated AdWidget instances (to ignore the error |
I hope this is enough. I have a dart file where I create my Inline Ad, as I have many files where I will want to show ads. I'm doing custom targeting as well so I pass those in as params. Then I gave a rough example setup of one of my feeds. There's quite a bit going on with my Pages/UI so I had to strip a lot of that away, but many of my pages may have additional custom cells & then at certain indexes, I want to show ads. To note, I did test this by bringing all of the ad logic into the file that has one of my feeds to see if that helped but I would get the same results. Ideally trying to keep from having to repeat the logic.
|
Thanks for your response and patience. The example above is incomplete and not minimal (using 3rd package, undefined widgets), so I borrow the sample code of OP at #892 and modified it as below. And I confirm I can see the issue now with Meanwhile, other AdSize (such as DemoScreen.Recording.2023-07-26.at.19.06.56.movComplete sample codeimport 'package:flutter/material.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
MobileAds.instance
..initialize()
..updateRequestConfiguration(RequestConfiguration(
testDeviceIds: <String>['20FB23B5E117EC42488FBC0A024F306F'],
));
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'ONE DEMO GOOGLE ADS APP'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
AdManagerBannerAd? underMainArticleBanner;
AdManagerBannerAd? aboveVideoSectionBanner;
AdManagerBannerAd? underVideoSectionBanner;
AdManagerBannerAd? underGlitchesSectionBanner;
static const _insets = 16.0;
double get _adWidth => MediaQuery.of(context).size.width - (2 * _insets);
late AdSize size;
AdSize? _adPlatformSize;
Future createUnderGlitchesBannerAd() async {
await AdManagerBannerAd(
adUnitId: '/6499/example/banner',
sizes: [size],
request: const AdManagerAdRequest(),
listener: AdManagerBannerAdListener(
onAdLoaded: (ad) {
setState(() {
underGlitchesSectionBanner = ad as AdManagerBannerAd;
setState(() async {
_adPlatformSize = await underGlitchesSectionBanner!.getPlatformAdSize();
});
});
},
onAdFailedToLoad: (ad, error) {
setState(() {
underGlitchesSectionBanner = null;
});
print('Ad load failed (code=${error.code} message=${error.message})');
ad.dispose();
},
),
).load();
}
Future createAboveVideoSectionBannerAd() async {
await AdManagerBannerAd(
adUnitId: '/6499/example/banner',
sizes: [AdSize.banner],
request: const AdManagerAdRequest(),
listener: AdManagerBannerAdListener(
onAdLoaded: (ad) {
setState(() {
aboveVideoSectionBanner = ad as AdManagerBannerAd;
});
},
onAdFailedToLoad: (ad, error) {
setState(() {
aboveVideoSectionBanner = null;
});
print('Ad load failed (code=${error.code} message=${error.message})');
ad.dispose();
},
),
).load();
}
Future createUnderVideoSectionBannerAd() async {
await AdManagerBannerAd(
adUnitId: '/6499/example/banner',
sizes: [AdSize.largeBanner],
request: const AdManagerAdRequest(),
listener: AdManagerBannerAdListener(
onAdLoaded: (ad) {
setState(() {
underVideoSectionBanner = ad as AdManagerBannerAd;
});
},
onAdFailedToLoad: (ad, error) {
setState(() {
underVideoSectionBanner = null;
});
print('Ad load failed (code=${error.code} message=${error.message})');
ad.dispose();
},
),
).load();
}
Future createUnderMainArticleBannerAd() async {
await AdManagerBannerAd(
adUnitId: '/6499/example/banner',
sizes: [AdSize.mediumRectangle],
request: const AdManagerAdRequest(),
listener: AdManagerBannerAdListener(
onAdLoaded: (ad) {
setState(() {
underMainArticleBanner = ad as AdManagerBannerAd;
});
},
onAdFailedToLoad: (ad, error) {
setState(() {
underMainArticleBanner = null;
});
print('Ad load failed (code=${error.code} message=${error.message})');
ad.dispose();
},
),
).load();
}
@override
void initState() {
super.initState();
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
size = AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(_adWidth.truncate());
createUnderMainArticleBannerAd();
createAboveVideoSectionBannerAd();
createUnderGlitchesBannerAd();
createUnderVideoSectionBannerAd();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: ListView(
children: [
Container(
height: 100,
color: Colors.blue,
alignment: Alignment.center,
child: Text('InlineAdaptiveBannerAdSize'),
),
underGlitchesSectionBanner != null
? Container(
color: const Color(0xFFD0D0D0),
// height: _adPlatformSize?.height.toDouble() ?? 0,
height: underGlitchesSectionBanner!.sizes[0].height.toDouble(),
width: MediaQuery.of(context).size.width,
child: AdWidget(ad: underGlitchesSectionBanner!),
)
: const SizedBox.shrink(),
Container(
height: 100,
color: Colors.blue,
alignment: Alignment.center,
child: Text('AdSize.mediumRectangle'),
),
underMainArticleBanner != null
? Container(
color: const Color(0xFFD0D0D0),
height: underMainArticleBanner!.sizes[0].height.toDouble(),
width: MediaQuery.of(context).size.width,
child: AdWidget(ad: underMainArticleBanner!),
)
: const SizedBox.shrink(),
Container(
height: 100,
color: Colors.blue,
alignment: Alignment.center,
child: Text('AdSize.banner'),
),
aboveVideoSectionBanner != null
? Container(
color: const Color(0xFFD0D0D0),
height: aboveVideoSectionBanner!.sizes[0].height.toDouble(),
width: MediaQuery.of(context).size.width,
child: AdWidget(ad: aboveVideoSectionBanner!),
)
: const SizedBox.shrink(),
Container(
height: 100,
color: Colors.blue,
alignment: Alignment.center,
child: Text('AdSize.largeBanner'),
),
underVideoSectionBanner != null
? Container(
color: const Color(0xFFD0D0D0),
height: underVideoSectionBanner!.sizes[0].height.toDouble(),
width: MediaQuery.of(context).size.width,
child: AdWidget(ad: underVideoSectionBanner!),
)
: const SizedBox.shrink(),
],
),
);
}
}
Reproduced the issue on the latest plugin version: |
flutter version -
3.7.12
dart version -
2.19.6
xcode version -
14.3.1
google_mobile_ads version -
2.4.0
I'm trying to create inline adaptive ads to display in a list view, but when trying to set the size using
getCurrentOrientationInlineAdaptiveBannerAdSize
, the ads will fail.I am using the inline example provided here, but changed it slightly:
If I replace size with either
AdSize.banner
orAdSize.mediumRectangle
, then the ad loads fine, otherwise I just get an empty space where the ad should be.The error I am getting is:
AdManagerBannerAd failed to load: LoadAdError(code: 1, domain: com.google.admob, message: Request Error: No ad to show., responseInfo: ResponseInfo(responseId: null, mediationAdapterClassName: null, adapterResponses: [], loadedAdapterResponseInfo: AdapterResponseInfo(adapterClassName: , latencyMillis: 0, description: , adUnitMapping: {}, adError: null, adSourceName: , adSourceId: , adSourceInstanceName: , adSourceInstanceId: )), responseExtras: {})
The text was updated successfully, but these errors were encountered: