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

[Flutter/Android] Ad loads but is not visible until I scroll list #875

Closed
kacpeer23 opened this issue Jun 30, 2023 · 5 comments
Closed

[Flutter/Android] Ad loads but is not visible until I scroll list #875

kacpeer23 opened this issue Jun 30, 2023 · 5 comments
Labels
duplicate This issue or pull request already exists

Comments

@kacpeer23
Copy link

kacpeer23 commented Jun 30, 2023

Hey, I have problem with ads in my flutter app. Sometimes when advertisement loads it's not visible until I scroll list where is this ad placed. When I scroll list ad appears. I'm using google_mobile_ads 2.4.0 version. I have native ads in my application. This issue occurs on android.

@darshankawar darshankawar added the in triage Issue currently being evaluated label Jun 30, 2023
@darshankawar
Copy link
Collaborator

@kacpeer23
Can you provide us a complete runnable minimal reproducible code sample along flutter doctor -v that shows the reported behavior ?

@darshankawar darshankawar added the feedback required Further information is requested label Jun 30, 2023
@kacpeer23
Copy link
Author

kacpeer23 commented Jun 30, 2023

@darshankawar
This is my Ad class:

class AdvertisementTile extends StatefulWidget {
  static RxBool forceRefresh = false.obs;

  AdvertisementTile({Key? key}) : super(key: key);

  @override
  State<AdvertisementTile> createState() => _AdvertisementTileState();
}

class _AdvertisementTileState extends State<AdvertisementTile> with AutomaticKeepAliveClientMixin {
  final EmailsController ctrl = Get.find<EmailsController>();
  late NativeAd native;
  bool isDarkMode = false;
  RxBool isAdLoaded = false.obs;
  RxBool isAdVisible = false.obs;
  RxBool adError = false.obs;
  StreamSubscription<dynamic>? _forceRefreshSubscription;

  @override
  void initState() {
    _forceRefreshSubscription?.cancel();
    _forceRefreshSubscription = AdvertisementTile.forceRefresh.listen((forceRefresh) {
      if (forceRefresh) {
        setState(() {
          isAdLoaded.value = false;
          isAdVisible.value = false;
          adError.value = false;
          _prepareNativeAd();
        });
      }
      AdvertisementTile.forceRefresh.value = false;
    });

    _prepareNativeAd();
    super.initState();
  }

  void _prepareNativeAd() {
    native = NativeAd.fromAdManagerRequest(//my configuration);
  }

  @override
  Widget build(BuildContext context) {
    isDarkMode = context.isDarkMode;
    native.customOptions = {'darkMode': isDarkMode};
    native.load();
    super.build(context);
 return Obx(() {
      return Visibility(
        visible: !adError.value,
        child: Stack(children: [
          Positioned.fill(
            child: Container(
                margin: const EdgeInsets.only(top: 4.3, bottom: 8.3, left: 5.3, right: 5.3),
                decoration: BoxDecoration(
                    color: context.theme.scaffoldBackgroundColor, borderRadius: BorderRadius.circular(16))),
          ),
          Container(
            decoration:
                BoxDecoration(color: context.theme.scaffoldBackgroundColor, borderRadius: BorderRadius.circular(16)),
            margin: const EdgeInsets.only(
              left: 5.3,
              right: 5.3,
              top: 4.3,
              bottom: 8.3,
            ),
            width: Get.width,
            height: 70,
            child: Obx(() {
              return Stack(children: [
                isAdLoaded.value ? AdWidget(ad: native) : Container(),
                Visibility(
                  visible: !isAdVisible.value,
                  child: const Center(
                    child: CircularProgressIndicator(),
                  ),
                )
              ]);
            }),
          ),
        ]),
      );
    });
  }

There is no logs about error or something. I have correct response from fromAdManagerRequest and ad should be visible, but it is not until I scroll

@github-actions github-actions bot removed the feedback required Further information is requested label Jun 30, 2023
@Wes1324
Copy link

Wes1324 commented Jul 2, 2023

I have implemented banner ads within a scroll view and am experiencing the same issue. I'm reluctant to push the ad implementation to production because the ads are not rendered until you scroll to them and then they take a few seconds to appear, which looks really janky.

I raised this on StackOverflow and included a link to a YouTube video of the behaviour I'm experiencing.

@KristijanZic
Copy link

I experience the same issue with ads in the ListView. It takes 2-5 seconds to load an ad, by that time the user has scrolled trough and none of the ads were loaded or shown.

@huycozy
Copy link
Collaborator

huycozy commented Aug 1, 2023

Closing this issue in favor of #887 since that issue is described in detail along with minimal sample code for further action. Please follow up on it for updates.

@huycozy huycozy closed this as not planned Won't fix, can't repro, duplicate, stale Aug 1, 2023
@huycozy huycozy added duplicate This issue or pull request already exists and removed in triage Issue currently being evaluated labels Aug 1, 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

5 participants