google admob可折叠的横幅不在flutter flutter中工作 我正在尝试使用Google Admob在我的Flutter应用中实现可折叠的横幅广告。但是,广告不会像预期的那样崩溃,它的行为就像常规的横幅广告。我跟随

问题描述 投票:0回答:1
"top"

额外的参数,但似乎没有生效。 我的代码: import 'package:flutter/material.dart'; import 'package:google_mobile_ads/google_mobile_ads.dart'; import 'package:insta/ads/consent_manager.dart'; class BannerAdWidget extends StatefulWidget { final String adUnitId; const BannerAdWidget({ super.key, required this.adUnitId, }); @override _BannerAdWidgetState createState() => _BannerAdWidgetState(); } class _BannerAdWidgetState extends State<BannerAdWidget> { BannerAd? _bannerAd; bool _isAdLoaded = false; final ConsentManager _consentManager = ConsentManager.instance; @override void didChangeDependencies() { super.didChangeDependencies(); _gatherConsentAndLoadAd(); } void _gatherConsentAndLoadAd() { _consentManager.gatherConsent((FormError? error) async { if (error == null) { bool canRequestAds = await _consentManager.canRequestAds(); if (canRequestAds) { _loadAd(); } else { debugPrint('User consent is not sufficient to request ads.'); } } else { debugPrint('Error gathering consent: ${error.message}'); } }); } Future<void> _loadAd() async { await _bannerAd?.dispose(); setState(() { _bannerAd = null; _isAdLoaded = false; }); final AnchoredAdaptiveBannerAdSize? adSize = await AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize( MediaQuery.of(context).size.width.truncate(), ); if (adSize == null) { debugPrint('Unable to get height of anchored banner.'); return; } const adRequest = AdRequest(extras: { "collapsible": "bottom", }); _bannerAd = BannerAd( adUnitId: widget.adUnitId, size: adSize, request: adRequest, listener: BannerAdListener( onAdLoaded: (Ad ad) { debugPrint('$ad loaded: ${ad.responseInfo}'); setState(() { _bannerAd = ad as BannerAd; _isAdLoaded = true; }); }, onAdFailedToLoad: (Ad ad, LoadAdError error) { debugPrint('Banner ad failed to load: $error'); ad.dispose(); }, ), ); _bannerAd!.load(); } Widget _buildAdWidget() { return OrientationBuilder( builder: (context, orientation) { if (_bannerAd != null && _isAdLoaded) { return Container( alignment: Alignment.bottomCenter, width: _bannerAd!.size.width.toDouble(), height: _bannerAd!.size.height.toDouble(), child: AdWidget(ad: _bannerAd!), ); } return const SizedBox.shrink(); }, ); } @override Widget build(BuildContext context) { return _buildAdWidget(); } @override void dispose() { _bannerAd?.dispose(); super.dispose(); } }

我期望的是:

用户与UI交互时,横幅广告应出现在底部并崩溃。

实际发生了什么:

横幅广告成功地负载,但它不会像预期的那样崩溃。

    问题:
目前Google Admob目前支持

曲线b

是启用可折叠横幅的正确方法?
    有任何已知的解决方法或替代方法可以实现这种行为?
  • 任何见解或建议将不胜感激!提前致谢。 🚀

  1. 目前Google Admob目前支持扑来的可折叠横幅? 是的,它支持在班纳拉德(Bannerad)中折叠。
  2. 是“可折叠”:“底部”启用可折叠横幅的正确方法?
    是的,它得到了支持
    
  3. 有任何已知的解决方法或替代方法可以实现这种行为? 您可以在下面看到此代码,我的工作是有效的。

"collapsible": "bottom"
flutter admob google-mobile-ads
1个回答
0
投票
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.