googleads / googleads-mobile-flutter

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

🐛 [iOS] Weird behavior of Ads inside listview with column #139

Closed diegocom closed 3 years ago

diegocom commented 3 years ago

Bug report

Describe the bug If an ad is inside a column in a ListView (or SingleChildScrollView) it doesn't stay anchored correctly to its position when it exits to the top during scrolling.

Check this video

Steps to reproduce

Steps to reproduce the behavior:

  1. Take the inline banner example from the codelabs
  2. Add a column as this:
    
    // COMPLETE: Import ad_helper.dart
    import 'package:admob_inline_ads_in_flutter/ad_helper.dart';

import 'package:admob_inline_ads_in_flutter/destination.dart';

// COMPLETE: Import google_mobile_ads.dart import 'package:google_mobile_ads/google_mobile_ads.dart';

import 'package:flutter/material.dart';

class BannerInlinePage extends StatefulWidget { final List entries;

BannerInlinePage({this.entries});

@override State createState() => _BannerInlinePageState(); }

class _BannerInlinePageState extends State { // COMPLETE: Add _kAdIndex static final _kAdIndex = 4;

// COMPLETE: Add a BannerAd instance BannerAd _ad;

// COMPLETE: Add _isAdLoaded bool _isAdLoaded = false;

@override void initState() { super.initState();

// COMPLETE: Create a BannerAd instance
_ad = BannerAd(
  adUnitId: AdManager.bannerAdUnitId,
  size: AdSize.mediumRectangle,
  request: AdRequest(),
  listener: AdListener(
    onAdLoaded: (_) {
      setState(() {
        _isAdLoaded = true;
      });
    },
    onAdFailedToLoad: (ad, error) {
      // Releases an ad resource when it fails to load
      ad.dispose();

      print('Ad load failed (code=${error.code} message=${error.message})');
    },
  ),
);

// COMPLETE: Load an ad
_ad.load();

}

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('AdMob Banner Inline Ad'), ), body: ListView.builder( // COMPLETE: Adjust itemCount based on the ad load state itemCount: widget.entries.length + (_isAdLoaded ? 1 : 0), itemBuilder: (context, index) { // COMPLETE: Render a banner ad if (_isAdLoaded && index == _kAdIndex) { final item = widget.entries[0];

        return Column(
          children: [
            Container(
              child: AdWidget(ad: _ad),
              width: _ad.size.width.toDouble(),
              height: 300.0,
              alignment: Alignment.center,
            ),
            ListTile(
              leading: Image.asset(
                item.asset,
                width: 48,
                height: 48,
                package: 'flutter_gallery_assets',
                fit: BoxFit.cover,
              ),
              title: Text(item.name),
              subtitle: Text(item.duration),
              onTap: () {
                print('Clicked ${item.name}');
              },
            ),
            ListTile(
              leading: Image.asset(
                item.asset,
                width: 48,
                height: 48,
                package: 'flutter_gallery_assets',
                fit: BoxFit.cover,
              ),
              title: Text(item.name),
              subtitle: Text(item.duration),
              onTap: () {
                print('Clicked ${item.name}');
              },
            ),
          ],
        );
      } else {
        // COMPLETE: Get adjusted item index from _getDestinationItemIndex()
        final item = widget.entries[_getDestinationItemIndex(index)];

        return ListTile(
          leading: Image.asset(
            item.asset,
            width: 48,
            height: 48,
            package: 'flutter_gallery_assets',
            fit: BoxFit.cover,
          ),
          title: Text(item.name),
          subtitle: Text(item.duration),
          onTap: () {
            print('Clicked ${item.name}');
          },
        );
      }
    },
  ),
);

}

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

// COMPLETE: Add _getDestinationItemIndex() int _getDestinationItemIndex(int rawIndex) { if (rawIndex >= _kAdIndex && _isAdLoaded) { return rawIndex - 1; } return rawIndex; } }


4. Build and scroll up and down. You can also use a SingleChildScrollView with a Column.

### Expected behavior

The ad should remain anchored to its position and disappear smoothly.

---

## Additional context

To solve this problem, just don't use columns. However, this did not happen in the previous version of the package (firebase_admob).

---

### Flutter doctor

Run `flutter doctor` and paste the output below:

<details><summary>Click To Expand</summary>

[✓] Flutter (Channel stable, 2.0.3, on Mac OS X 10.15.7 19H2 darwin-x64, locale it-IT) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2) [✓] Xcode - develop for iOS and macOS [✓] Chrome - develop for the web [✓] Android Studio (version 4.1) [✓] VS Code (version 1.54.3) [✓] Connected device (3 available) • No issues found!


</details>

---

### Flutter dependencies

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

<details><summary>Click To Expand</summary>

Dart SDK 2.12.2 Flutter SDK 2.0.3 admob_inline_ads_in_flutter 1.0.0+1

dependencies:

dev dependencies:

transitive dependencies:


blasten commented 3 years ago

This appears to be an issue in the Flutter engine

diegocom commented 3 years ago

This appears to be an issue in the Flutter engine

So could it be a problem with all Native Views?

wazasoft commented 3 years ago

I experience the same issue with scrolling link - mentioned in the second para on my comment in that issue.

I am not sure what was the point of releasing this half-baked plugin to public? Just a waste of time and effort! They even went ahead and shot a video tutorial for this plugin. Looks like the dev team is busy adding "new" features while completely ignoring the fact that plugin is not usable.

Sorry if I was a bit harsh, but we are switching back to an old "orphaned" admob plugin that some independent dev did on his own. No one is updating it anymore but atleast its stable!

3eif commented 3 years ago

Agreed, I've experienced many random bugs and issues with this plugin as well. I've also noticed that my app's performance dropped by a significant amount ever since I started using this plugin for some reason.

I've spent the past few weeks trying to get native ads working. At this point though it's causing a large delay for my app update which is ready to be pushed. So I might have to use another ad package for now as well.

I really hope that Flutter receives more support for mobile ads, especially native ads, in the future.

diegocom commented 3 years ago

@Tetracyl You are right, performance also dropped a lot with this new plugin

dazuaz commented 3 years ago

This issue from another package seems to be related and explains a bit whats going on https://github.com/bdlukaa/native_admob_flutter/issues/22

mustafa-707 commented 3 years ago

same here it stuck on top of the screen and when scroll it stuck like a web-view behaviour , for me it just happend when i upgraded my flutter to 2 , with 1.22.6 it was worked without that , the problem here if you want to back to the old plugin like admob or ad_manager the plugins is deprecated with the new firebase and cant use new fixes of the notification and firebase core 1.0.2 or 0.7.0 .. i guess this issue must be in the top of the priority of this plugin because its for sure a stopper

mustafa-707 commented 3 years ago

i got this logs in my iPhone 6s Plus , is it related to this issue ?

WF: _userSettingsForUser mobile: {
    filterBlacklist =     (
    );
    filterWhitelist =     (
    );
    restrictWeb = 1;
    useContentFilter = 0;
    useContentFilterOverrides = 0;
    whitelistEnabled = 0;
}
WF: _WebFilterIsActive returning: NO
WF: _userSettingsForUser mobile: {
    filterBlacklist =     (
    );
    filterWhitelist =     (
    );
    restrictWeb = 1;
    useContentFilter = 0;
    useContentFilterOverrides = 0;
    whitelistEnabled = 0;
}
WF: _WebFilterIsActive returning: NO
flutter: PublisherBannerAd loaded.
Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service

some time it cause a crashes

Nader2004 commented 3 years ago

Any workaround for this issue, because it's blocking me for publishing the app.

mustafa-707 commented 3 years ago

@Nader2004 Same here , i gave up already 0 updates and no one care , the problem with flutter 2 not with the plugin after much experiments , i just got back to flutter 1.22.6 and also i got back to flutter_google_ad_manager cause this plugin have much problems with old android and it cause much crashes and it's have a bad performance , but for real i used it with rewarded ads cause it's better but the interstitial and the banners still have much issues

blasten commented 3 years ago

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