Skip to content
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

Banner Ads are not cut off and look horrible #928

Closed
patolax opened this issue Oct 9, 2023 · 4 comments
Closed

Banner Ads are not cut off and look horrible #928

patolax opened this issue Oct 9, 2023 · 4 comments
Labels
duplicate This issue or pull request already exists

Comments

@patolax
Copy link

patolax commented Oct 9, 2023

I have tried several Google forums to get this fixed or obtain a proper implementation method.

This is the last response I got. Not sure where to go from here.
image

I can't release the app ads shown like this. It looks horrible.
image

This is my code. Please provide me a working solution.

class AdBanner extends StatefulWidget {
  const AdBanner({Key? key}) : super(key: key);

  @override
  State<AdBanner> createState() => _AdBannerState();
}

class _AdBannerState extends State<AdBanner> {
  BannerAd? _inlineAdaptiveAd;
  bool _isLoaded = false;

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      var windowwidth = MediaQuery.of(context).size.width.truncate();
      _loadAd(windowwidth);
    });
  }

  void _loadAd(int windowwidth) async {
    await _inlineAdaptiveAd?.dispose();
    // Get an inline adaptive size for the current orientation.
    AdSize size = AdSize.banner;
    size = (await AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(
        windowwidth)) as AdSize;

    _inlineAdaptiveAd = BannerAd(
      adUnitId: AdHelper.bannerAdUnitId,
      size: size,
      request: const AdRequest(),
      listener: BannerAdListener(
        onAdLoaded: (Ad ad) async {
          debugPrint('Inline BannerAdListener onAdLoaded');
          if (mounted) {
            setState(() {
              _isLoaded = true;
            });
          }
        },
        onAdFailedToLoad: (Ad ad, LoadAdError error) {
          debugPrint('Inline adaptive banner failedToLoad: $error');
          _isLoaded = false;
          ad.dispose();
        },
      ),
    );
    await _inlineAdaptiveAd!.load();
  }

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

  @override
  void dispose() {
    _inlineAdaptiveAd?.dispose();

    super.dispose();
  }
}
@patolax patolax changed the title Ad is not cut off and looks horrible Banner Ads are not cut off and look horrible Oct 9, 2023
@huycozy huycozy added the in triage Issue currently being evaluated label Oct 9, 2023
@huycozy
Copy link
Collaborator

huycozy commented Oct 9, 2023

Hi @patolax
When checking this issue on my device Realme 6, Android 11, the banner looks fine in the center:

Screenshot 2023-10-09 at 18 43 30

Which device are you seeing the issue?

Could you try running native sample AdaptiveBannerExample on your device to see if the issue also occurs?

@huycozy huycozy added the feedback required Further information is requested label Oct 9, 2023
@patolax
Copy link
Author

patolax commented Oct 9, 2023

This is from my own Android app using admob integration in Java running on the same device.

As you can see the ad is working fine without any miss alignments.

The issue is when I use fultter integration.
May others have reported this #261 (comment)

This is my test device https://www.motorola.com.au/smartphone-motorola-moto-g22/p

@github-actions github-actions bot removed the feedback required Further information is requested label Oct 9, 2023
@patolax
Copy link
Author

patolax commented Oct 10, 2023

@huycozy
Copy link
Collaborator

huycozy commented Oct 11, 2023

Thanks for checking this. I will re-open #261 as many reports along with information there. Please leave there a comment (or update your comment) with a demo above and device information as well.

Closing this as a duplicate.

@huycozy huycozy closed this as not planned Won't fix, can't repro, duplicate, stale Oct 11, 2023
@huycozy huycozy added duplicate This issue or pull request already exists and removed in triage Issue currently being evaluated labels Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants