How to prevent AdMob ads affecting app screen size and orientation

Viewed 37

I have a Flutter app with Google Mobile Ads

I have painstakingly made the app work with different screen sizes and orientations. But when I play the ad (rewarded ad in immersive mode), the ad often changes the screen orientation which causes UI overflow errors in the app behind the ad. I have also noticed that the ad changes the screen height from 781dp to 829dp on Pixel 4 emulator. Not sure how is this even possible... This happens in onUserEarnedReward callback.

Anyway, is there any way to handle this elegantly? Or is this a bug in mobile ads package? It is not causing an app to crash, but is annoying having these UI errors.

The problems are visibile by printing MediaQuery.of(context).size.width and MediaQuery.of(context).size.height from below events:

  • setImmersiveMode - changes orientation if ad is in different orientation than the app
  • onUserEarnedReward - changes the screen height dp value!?

See below code from the package example:

 void _showRewardedAd() {
    if (_rewardedAd == null) {
      print('Warning: attempt to show rewarded before loaded.');
      return;
    }
    _rewardedAd!.fullScreenContentCallback = FullScreenContentCallback(
      onAdShowedFullScreenContent: (RewardedAd ad) =>
          print('ad onAdShowedFullScreenContent.'),
      onAdDismissedFullScreenContent: (RewardedAd ad) {
        print('$ad onAdDismissedFullScreenContent.');
        ad.dispose();
        _createRewardedAd();
      },
      onAdFailedToShowFullScreenContent: (RewardedAd ad, AdError error) {
        print('$ad onAdFailedToShowFullScreenContent: $error');
        ad.dispose();
        _createRewardedAd();
      },
    );

    _rewardedAd!.setImmersiveMode(true);
    _rewardedAd!.show(
        onUserEarnedReward: (AdWithoutView ad, RewardItem reward) {
      print('$ad with reward $RewardItem(${reward.amount}, ${reward.type})');
    });
    _rewardedAd = null;
  }

1 Answers

RewardedInterstitial Ad is not release yet.You can't use RewardedInterstitial Ad in release mode, use Interstitial Ad instead of RewardedInterstitial Ad.

Related