1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] AdManagerBannerAd requesting multiple heights, but not returning height for the ad,...

Discussão em 'Mobile' iniciado por Stack, Novembro 8, 2024 às 11:43.

  1. Stack

    Stack Membro Participativo

    i am using google_mobile_ads: ^5.2.0 to display adds on my flutter app. I need to request and display 3 different sizes of banner ads from google.

    This ad is supposed to be show in a scrollable column so i must set the height of it, the problem is that when the add is loaded i don't have the information about the loaded ad, it could be any of the three. If i don't set the height it is either hidden or there is an error that the height cannot be infinite.

    note: in the snippet in only set the temporary size, because i don't know how to get the correct one.

    Future<void> loadAd() async {
    _bannerAd = AdManagerBannerAd(
    adUnitId: adUnitId,
    request: const AdManagerAdRequest(),
    sizes: [
    const AdSize(width: 300, height: 100),
    const AdSize(width: 300, height: 250),
    const AdSize(width: 300, height: 600)
    ],
    listener: AdManagerBannerAdListener(
    onAdLoaded: (ad) {
    if (!mounted) {
    ad.dispose();
    return;
    }
    debugPrint('$ad loaded.');
    setState(() {
    _isLoaded = true;
    });
    },
    onAdFailedToLoad: (ad, error) {
    debugPrint('AdManagerBannerAd failed to load: $error');
    ad.dispose();
    },
    ))
    ..load();
    }

    @override
    void dispose() {

    _bannerAd?.dispose();
    super.dispose();
    }

    @override
    Widget build(BuildContext context) {
    return _isLoaded && _bannerAd != null
    ? Align(
    alignment: Alignment.bottomCenter,
    child: SafeArea(
    child: SizedBox(
    width: _bannerAd!.sizes[0].width.toDouble(),
    height: _bannerAd!.sizes[0].height.toDouble(),
    child: AdWidget(ad: _bannerAd!),
    ),
    ),
    )
    : const SizedBox
    .shrink();
    }


    please help.

    Continue reading...

Compartilhe esta Página