googleads / googleads-mobile-flutter

A Flutter plugin for the Google Mobile Ads SDK
Apache License 2.0
344 stars 287 forks source link

šŸ› AdMob inline banner is shown on iOS on top of the screen too (why?) #115

Closed MooDone closed 3 years ago

MooDone commented 3 years ago

Bug report

Describe the bug I inserted a AdMob inline banner in a listview like described in the official codelab. The test-mode-banner is shown right in the listview on android and iOS. But on iOS-device the banner is shown too on the top of my screen and overlays my listview.

Steps to reproduce

This the code of my banner-widget:

import '../widgets/progress.dart';
import 'package:flutter/material.dart';
import '../google_mobile_ads/ad_helper.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
import '../pages/home_page.dart';

class AdGrid03GoogleBanner extends StatefulWidget {
  int bannerWidth;
  int bannerHeight;

  AdGrid03GoogleBanner({this.bannerHeight, this.bannerWidth});

  @override
  _AdGrid03GoogleBannerState createState() => _AdGrid03GoogleBannerState();
}

class _AdGrid03GoogleBannerState extends State<AdGrid03GoogleBanner> {
  BannerAd _ad;
  bool _isAdLoaded = false;
  int bannerWidth;
  int bannerHeight;

  @override
  void initState() {
    super.initState();
    bannerWidth = widget.bannerWidth;
    bannerHeight = widget.bannerHeight;
    AdSize adSize = AdSize(width: bannerWidth, height: bannerHeight);

    _ad = BannerAd(
      adUnitId: AdHelper.bannerAdUnitId,
      //size: AdSize.banner,
      size: adSize,
      request: AdRequest(),
      listener: AdListener(
        onAdLoaded: (_) {
          setState(() {
            _isAdLoaded = true;
          });
        },
        onAdFailedToLoad: (_, error) {
          print('Ad load failed (code=${error.code} message=${error.message})');
        },
      ),
    );

    // TODO: Load an ad
    _ad.load();
  }

  @override
  void dispose() {
    // TODO: Dispose a BannerAd object
    _ad?.dispose();

    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: _isAdLoaded ? AdWidget(ad: _ad) : circularProgress(),
      width: _ad.size.width.toDouble(),
      height: double.parse((bannerHeight * 1.5).toString()),
      alignment: Alignment.center,
    );
  }
}

Expected behavior

I don't expected that the banner is shown on the top of my screen too.


Additional context

Add any other context about the problem here.


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` flutter doctor -v [āœ“] Flutter (Channel stable, 2.0.2, on macOS 11.2.3 20D91 darwin-x64, locale de-DE) ā€¢ Flutter version 2.0.2 at /Users/michael/Documents/Developer/flutter ā€¢ Framework revision 8962f6dc68 (9 days ago), 2021-03-11 13:22:20 -0800 ā€¢ Engine revision 5d8bf811b3 ā€¢ Dart version 2.12.1 [āœ“] Android toolchain - develop for Android devices (Android SDK version 30.0.2) ā€¢ Android SDK at /Users/michael/Library/Android/sdk ā€¢ Platform android-30, build-tools 30.0.2 ā€¢ Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java ā€¢ Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) ā€¢ All Android licenses accepted. [āœ“] Xcode - develop for iOS and macOS ā€¢ Xcode at /Applications/Xcode.app/Contents/Developer ā€¢ Xcode 12.4, Build version 12D4e ā€¢ CocoaPods version 1.10.1 [āœ—] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome) ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable. [āœ“] Android Studio (version 4.0) ā€¢ Android Studio at /Applications/Android Studio.app/Contents ā€¢ Flutter plugin version 49.0.2 ā€¢ Dart plugin version 193.7547 ā€¢ Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) [āœ“] Connected device (1 available) ā€¢ iPhone 12 Pro Max (mobile) ā€¢ F2E4F560-8466-43F3-A33B-41039F6F4F8E ā€¢ ios ā€¢ com.apple.CoreSimulator.SimRuntime.iOS-14-4 (simulator) ```

Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand ``` flutter pub deps Dart SDK 2.12.1 Flutter SDK 2.0.2 myApp 1.0.0+1 |-- animator 3.0.0 | |-- flutter... | '-- states_rebuilder 4.0.0+1 | |-- collection... | '-- flutter... |-- cached_network_image 3.0.0-nullsafety | |-- flutter... | |-- flutter_cache_manager 3.0.0-nullsafety.1 | | |-- clock... | | |-- collection... | | |-- file 6.1.0 | | | |-- meta... | | | '-- path... | | |-- flutter... | | |-- http... | | |-- image... | | |-- path... | | |-- path_provider... | | |-- pedantic... | | |-- rxdart... | | |-- sqflite 2.0.0+2 | | | |-- flutter... | | | |-- path... | | | '-- sqflite_common 2.0.0+2 | | | |-- meta... | | | |-- path... | | | '-- synchronized 3.0.0 | | '-- uuid... | '-- octo_image 1.0.0-nullsafety.1 | |-- flutter... | '-- flutter_blurhash 0.5.4-nullsafety.0 | |-- flutter... | |-- meta... | '-- pedantic... |-- cloud_firestore 1.0.1 | |-- cloud_firestore_platform_interface 4.0.0 | | |-- collection... | | |-- firebase_core... | | |-- flutter... | | |-- meta... | | '-- plugin_platform_interface... | |-- cloud_firestore_web 1.0.1 | | |-- cloud_firestore_platform_interface... | | |-- firebase_core... | | |-- firebase_core_web... | | |-- flutter... | | |-- flutter_web_plugins... | | '-- js... | |-- firebase_core... | |-- firebase_core_platform_interface... | |-- flutter... | '-- meta... |-- cupertino_icons 1.0.2 |-- firebase_analytics 7.1.1 | |-- firebase_analytics_platform_interface 1.1.0 | | |-- flutter... | | '-- meta... | |-- firebase_analytics_web 0.2.0+1 | | |-- firebase 9.0.0 | | | |-- http... | | | |-- http_parser... | | | '-- js... | | |-- firebase_analytics_platform_interface... | | |-- flutter... | | |-- flutter_web_plugins... | | '-- meta... | |-- firebase_core... | |-- flutter... | '-- meta... |-- firebase_auth 1.0.1 | |-- firebase_auth_platform_interface 4.0.0 | | |-- firebase_core... | | |-- flutter... | | |-- meta... | | '-- plugin_platform_interface... | |-- firebase_auth_web 1.0.2 | | |-- firebase_auth_platform_interface... | | |-- firebase_core... | | |-- firebase_core_web... | | |-- flutter... | | |-- flutter_web_plugins... | | |-- http_parser... | | |-- intl... | | |-- js... | | '-- meta... | |-- firebase_core... | |-- firebase_core_platform_interface... | |-- flutter... | '-- meta... |-- firebase_core 1.0.1 | |-- firebase_core_platform_interface 4.0.0 | | |-- flutter... | | |-- meta... | | '-- plugin_platform_interface 2.0.0 | | '-- meta... | |-- firebase_core_web 1.0.1 | | |-- firebase_core_platform_interface... | | |-- flutter... | | |-- flutter_web_plugins... | | |-- js 0.6.3 | | '-- meta... | |-- flutter... | '-- meta... |-- firebase_messaging 9.0.0 | |-- firebase_core... | |-- firebase_core_platform_interface... | |-- firebase_messaging_platform_interface 2.0.0 | | |-- firebase_core... | | |-- flutter... | | |-- meta... | | '-- plugin_platform_interface... | |-- firebase_messaging_web 1.0.1 | | |-- firebase_core... | | |-- firebase_core_web... | | |-- firebase_messaging_platform_interface... | | |-- flutter... | | |-- flutter_web_plugins... | | |-- js... | | '-- meta... | |-- flutter... | '-- meta... |-- firebase_storage 8.0.0 | |-- firebase_core... | |-- firebase_core_platform_interface... | |-- firebase_storage_platform_interface 2.0.0 | | |-- collection... | | |-- firebase_core... | | |-- flutter... | | |-- meta... | | '-- plugin_platform_interface... | |-- firebase_storage_web 1.0.1 | | |-- async... | | |-- firebase_core... | | |-- firebase_core_web... | | |-- firebase_storage_platform_interface... | | |-- flutter... | | |-- flutter_web_plugins... | | |-- http... | | |-- js... | | '-- meta... | '-- flutter... |-- flutter 0.0.0 | |-- characters 1.1.0 | |-- collection 1.15.0 | |-- meta 1.3.0 | |-- sky_engine 0.0.99 | |-- typed_data 1.3.0 | | '-- collection... | '-- vector_math 2.1.0 |-- flutter_google_places_hoc081098 1.0.0-nullsafety.0 | |-- collection... | |-- flutter... | |-- google_api_headers 1.0.0 | | |-- flutter... | | '-- package_info 2.0.0 | | '-- flutter... | |-- google_maps_webservice... | |-- http... | |-- listenable_stream 1.0.0-nullsafety.1 | | |-- flutter... | | '-- rxdart... | '-- rxdart 0.26.0 |-- flutter_localizations 0.0.0 | |-- characters... | |-- clock 1.1.0 | |-- collection... | |-- flutter... | |-- intl 0.17.0 | | |-- clock... | | '-- path... | |-- meta... | |-- path 1.8.0 | |-- typed_data... | '-- vector_math... |-- flutter_spinkit 5.0.0 | '-- flutter... |-- flutter_test 0.0.0 | |-- async 2.5.0 | | '-- collection... | |-- boolean_selector 2.1.0 | | |-- source_span... | | '-- string_scanner... | |-- characters... | |-- charcode 1.2.0 | |-- clock... | |-- collection... | |-- fake_async 1.2.0 | | |-- clock... | | '-- collection... | |-- flutter... | |-- matcher 0.12.10 | | '-- stack_trace... | |-- meta... | |-- path... | |-- source_span 1.8.0 | | |-- charcode... | | |-- collection... | | |-- path... | | '-- term_glyph... | |-- stack_trace 1.10.0 | | '-- path... | |-- stream_channel 2.1.0 | | '-- async... | |-- string_scanner 1.1.0 | | |-- charcode... | | '-- source_span... | |-- term_glyph 1.2.0 | |-- test_api 0.2.19 | | |-- async... | | |-- boolean_selector... | | |-- collection... | | |-- matcher... | | |-- meta... | | |-- path... | | |-- source_span... | | |-- stack_trace... | | |-- stream_channel... | | |-- string_scanner... | | '-- term_glyph... | |-- typed_data... | '-- vector_math... |-- geocoder 0.2.1 | |-- flutter... | '-- meta... |-- geolocator 7.0.1 | |-- flutter... | |-- geolocator_platform_interface 2.0.0 | | |-- flutter... | | |-- meta... | | |-- plugin_platform_interface... | | '-- vector_math... | '-- geolocator_web 2.0.1 | |-- flutter... | |-- flutter_web_plugins... | '-- geolocator_platform_interface... |-- google_maps_webservice 0.0.20-nullsafety.2 | |-- http... | |-- json_annotation 4.0.0 | '-- meta... |-- google_mobile_ads 0.11.0+4 | |-- flutter... | '-- meta... |-- http 0.13.0 | |-- http_parser 4.0.0 | | |-- charcode... | | |-- collection... | | |-- source_span... | | |-- string_scanner... | | '-- typed_data... | |-- meta... | |-- path... | '-- pedantic 1.11.0 |-- image 3.0.1 | |-- archive 3.1.2 | | |-- crypto... | | '-- path... | |-- meta... | '-- xml 5.0.2 | |-- collection... | |-- meta... | '-- petitparser 4.0.2 | '-- meta... |-- image_picker 0.7.2+1 | |-- flutter... | |-- flutter_plugin_android_lifecycle 2.0.0 | | '-- flutter... | '-- image_picker_platform_interface 2.0.1 | |-- flutter... | |-- http... | |-- meta... | '-- plugin_platform_interface... |-- material_design_icons_flutter 4.0.5955 | '-- flutter... |-- path_provider 2.0.1 | |-- flutter... | |-- path_provider_linux 2.0.0 | | |-- flutter... | | |-- path... | | |-- path_provider_platform_interface... | | '-- xdg_directories 0.2.0 | | |-- meta... | | |-- path... | | '-- process 4.1.0 | | |-- file... | | |-- path... | | '-- platform... | |-- path_provider_macos 2.0.0 | | '-- flutter... | |-- path_provider_platform_interface 2.0.1 | | |-- flutter... | | |-- meta... | | |-- platform 3.0.0 | | '-- plugin_platform_interface... | '-- path_provider_windows 2.0.0 | |-- ffi 1.0.0 | |-- flutter... | |-- meta... | |-- path... | |-- path_provider_platform_interface... | '-- win32 2.0.3 | '-- ffi... |-- photo_view 0.11.1 | '-- flutter... |-- preload_page_view 0.1.5 | '-- flutter... |-- provider 5.0.0 | |-- collection... | |-- flutter... | '-- nested 1.0.0 | '-- flutter... |-- shared_preferences 0.5.7+3 | |-- flutter... | |-- meta... | |-- shared_preferences_macos 0.0.1+10 | | |-- flutter... | | '-- shared_preferences_platform_interface... | |-- shared_preferences_platform_interface 1.0.4 | | |-- flutter... | | '-- meta... | '-- shared_preferences_web 0.1.2+7 | |-- flutter... | |-- flutter_web_plugins 0.0.0 | | |-- characters... | | |-- collection... | | |-- flutter... | | |-- js... | | |-- meta... | | |-- typed_data... | | '-- vector_math... | |-- meta... | '-- shared_preferences_platform_interface... |-- timeago 3.0.2 '-- uuid 3.0.1 '-- crypto 3.0.0 |-- collection... '-- typed_data... ```

Rodrig0v commented 3 years ago

This also happens randomly with Native ads on both iOS and android in nestedscrollviews, singlescrollviews and listviews. The ad will briefly flash on top of the list and then correct itself. Sometimes it might even stay at the top until the user decides to scroll.

MooDone commented 3 years ago

the problem still exists as described below. Do you need more informations?

eliabieri commented 3 years ago

I have the same problem.

ItsCalebJones commented 3 years ago

Here's my reproduction of this issue: https://i.imgur.com/jmJ3oSM.png

I have the widget down past the bottom of the visible view - it loads and pops in at the top of the parent which is a SingleChildScrollView.

Source: https://github.com/ItsCalebJones/SpaceLaunchNow-Flutter/blob/feature/ads_update/lib/views/launchdetails/launch_detail_body.dart

MooDone commented 3 years ago

the problem still exists as described below. Do you need more informations?

bdlukaa commented 3 years ago

This is an issue with hybrid composition, not with the library. Tho in Virtual Display could be used instead of hybrid composition

royibernthal commented 3 years ago

Joining the issue

sooxt98 commented 3 years ago

My ListView is flooded with ads when scrolling image

bdlukaa commented 3 years ago

https://github.com/flutter/flutter/issues/76097

maheshj01 commented 3 years ago

Hi @MooDone, thanks for filing the issue, Anyone who is facing this issue could you please share a complete code sample, I verified this issue with the latest google_mobile_Ads: 0.13.3 and it seems to work fine for me.

code sample ```dart import 'dart:ui'; import 'package:flutter/material.dart'; import 'package:google_mobile_ads/google_mobile_ads.dart'; void main() { WidgetsFlutterBinding.ensureInitialized(); MobileAds.instance.initialize(); runApp(BannerApp()); } class BannerApp extends StatelessWidget { const BannerApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return MaterialApp(home: BannerSample1()); } } class BannerSample1 extends StatefulWidget { const BannerSample1({Key? key}) : super(key: key); @override _BannerSample1State createState() => _BannerSample1State(); } class _BannerSample1State extends State { late BannerAd _bannerAd; bool isAdloaded = false; @override void initState() { super.initState(); _bannerAd = BannerAd( adUnitId: BannerAd.testAdUnitId, size: AdSize.banner, request: AdRequest(), listener: BannerAdListener( onAdLoaded: (Ad ad) { print('$BannerAd loaded.'); setState(() { isAdloaded = true; }); }, ), ); _bannerAd.load(); } @override void dispose() { // TODO: implement dispose _bannerAd.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text('Banner Ad')), body: ListView.builder( itemCount: 20, itemBuilder: (context, index) { if (isAdloaded && index == 10) { return Container( child: AdWidget(ad: _bannerAd), width: _bannerAd.size.width.toDouble(), height: 72.0, alignment: Alignment.center, ); } else { return ListTile( title: Text('Item $index'), ); } }, )); } } ```
flutter doctor -v ``` [āœ“] Flutter (Channel stable, 2.2.3, on macOS 11.4 20F71 darwin-arm, locale en-GB) ā€¢ Flutter version 2.2.3 at /Users/mahesh/Documents/flutter ā€¢ Framework revision f4abaa0735 (4 weeks ago), 2021-07-01 12:46:11 -0700 ā€¢ Engine revision 241c87ad80 ā€¢ Dart version 2.13.4 [āœ“] Android toolchain - develop for Android devices (Android SDK version 30.0.3) ā€¢ Android SDK at /Users/mahesh/Library/Android/sdk ā€¢ Platform android-30, build-tools 30.0.3 ā€¢ ANDROID_HOME = /Users/mahesh/Library/Android/sdk ā€¢ Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java ā€¢ Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264) ā€¢ All Android licenses accepted. [āœ“] Xcode - develop for iOS and macOS ā€¢ Xcode at /Applications/Xcode.app/Contents/Developer ā€¢ Xcode 12.4, Build version 12D4e ā€¢ CocoaPods version 1.10.1 [āœ“] Chrome - develop for the web ā€¢ Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [āœ“] Android Studio (version 4.2) ā€¢ Android Studio at /Applications/Android Studio.app/Contents ā€¢ Flutter plugin can be installed from: šŸ”Ø https://plugins.jetbrains.com/plugin/9212-flutter ā€¢ Dart plugin can be installed from: šŸ”Ø https://plugins.jetbrains.com/plugin/6351-dart ā€¢ Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264) [āœ“] IntelliJ IDEA Community Edition (version 2021.1.2) ā€¢ IntelliJ at /Applications/IntelliJ IDEA CE.app ā€¢ Flutter plugin version 57.0.5 ā€¢ Dart plugin version 211.7233 [āœ“] VS Code (version 1.58.0) ā€¢ VS Code at /Applications/Visual Studio Code.app/Contents ā€¢ Flutter extension version 3.24.0 [āœ“] Connected device (4 available) ā€¢ Redmi K20 Pro (mobile) ā€¢ android-arm64 ā€¢ Android 11 (API 30) ā€¢ iPhone 12 Pro Max (mobile) ā€¢ 6A434744-B348-4FB3-AB10-131292174456 ā€¢ ios ā€¢ com.apple.CoreSimulator.SimRuntime.iOS-14-4 (simulator) ā€¢ macOS (desktop) ā€¢ macos ā€¢ darwin-arm64 ā€¢ macOS 11.4 20F71 darwin-arm ā€¢ Chrome (web) ā€¢ chrome ā€¢ web-javascript ā€¢ Google Chrome 92.0.4515.107 ā€¢ No issues found! ```

Thanks

timothyhoang-google commented 3 years ago

Hi everyone,

For anyone still facing this issue, if upgrading to google_mobile_ads: 0.13.3+ does not resolve the problem, could you share a complete code sample?

If there are no reproducible samples using google_mobile_ads: 0.13.3+, we'll close this issue at the end of next week 09/17/21.

maheshj01 commented 3 years ago

Labeling this issue as fixed, as no longer reproducible.