Appodeal-Flutter-Plugin icon indicating copy to clipboard operation
Appodeal-Flutter-Plugin copied to clipboard

Banner view content not displayed after back navigation

Open Darkos-den opened this issue 2 years ago • 9 comments

Steps for reproducing:

  • open screen with appodeal banner view
  • push new screen
  • tap back

Expected result: banner view content displayed normally; Actual result: banner view content not displayed;

Darkos-den avatar Apr 10 '22 19:04 Darkos-den

@Darkos-den Hello! Thanks for your issue, we started to investigate this behavior.

da2gl avatar Apr 21 '22 13:04 da2gl

@Darkos-den Hi! Can you attach logs from Appodeal SDK?

da2gl avatar Jun 02 '22 12:06 da2gl

Same problem.. Any solution?

marcos93net avatar Jun 13 '22 20:06 marcos93net

@Darkos-den Hi! Can you attach logs from Appodeal SDK?

@da2gl When returning from another screen, the library does not generate any logs. As far as I understand, the library considers that the banner has already been initialized and because of this it is not rendered.

Darkos-den avatar Jun 14 '22 10:06 Darkos-den

Same problem.. Any solution?

@marcos93net I made a small hack to solve this issue - every time I return from another screen, I change the state for some object that I use to draw the banner.

Page widget:

ValueListenableBuilder<int>(
                    valueListenable: AdUtil().invalidateBannerAd,
                    builder: (_, value, ___) {
                      if (value % 2 == 0) {
                        return Container();
                      }
                      return AppodealBanner(adSize: AppodealBannerSize.BANNER);
                    },
                  )

AdUtil:

final ValueNotifier<int> invalidateBannerAd = ValueNotifier<int>(1);

  void invalidateBanner() async {
    await Future.delayed(Duration(milliseconds: 50)).then((value) {
      if (invalidateBannerAd.value > 1000) {
        invalidateBannerAd.value = 1;
      } else {
        invalidateBannerAd.value = invalidateBannerAd.value + 1;
      }
    });
    await Future.delayed(Duration(milliseconds: 50)).then((value) {
      if (invalidateBannerAd.value > 1000) {
        invalidateBannerAd.value = 1;
      } else {
        invalidateBannerAd.value = invalidateBannerAd.value + 1;
      }
    });
  }

App widget:

MaterialApp(
          navigatorObservers: [
            AppFirebaseAnalyticsObserver(
              onPop: () {
                AdUtil().invalidateBanner();
              }
            ),
          ],
        )

This is a rather dirty solution, but so far I have not come up with anything better.

Darkos-den avatar Jun 14 '22 10:06 Darkos-den

Is there any update. I'm using version 3.0.0 and this issue is still alive

phamanhminh1208 avatar Oct 23 '22 14:10 phamanhminh1208

@phamanhminh1208 @Darkos-den Hello! We're back to the banner view issue, but we cannot reproduce this behavior. If you could attach a project or snippets of the display and initialization code, it would help us fix the problem. And tell me, do you show the banner after initialization or before it? Thanks.

da2gl avatar Jan 24 '23 10:01 da2gl

Steps for reproducing:

  • open screen with appodeal banner view
  • push new screen
  • tap back

Expected result: banner view content displayed normally; Actual result: banner view content not displayed;

Hello, same problem for me.

@phamanhminh1208 @Darkos-den Hello! We're back to the banner view issue, but we cannot reproduce this behavior. If you could attach a project or snippets of the display and initialization code, it would help us fix the problem. And tell me, do you show the banner after initialization or before it? Thanks.

I hope the sample screencast and code snippet will help.

banner_view_bug

Here's the sample code to reproduce the issue.

class FirstScreen extends StatelessWidget {
  const FirstScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('First Screen'),
      ),
      body: Center(
        child: ElevatedButton(
          child: const Text('Second Screen'),
          onPressed: () {
            Navigator.push(
              context,
              MaterialPageRoute(builder: (context) => const SecondScreen()),
            );
          },
        ),
      ),
      bottomNavigationBar: const Column(
        mainAxisSize: MainAxisSize.min,
        mainAxisAlignment: MainAxisAlignment.end,
        children: [
          Center(
            child: AppodealBanner(
              adSize: AppodealBannerSize.BANNER,
            ),
          ),
        ],
      ),
    );
  }
}

class SecondScreen extends StatelessWidget {
  const SecondScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Second Screen'),
      ),
      body: Center(
        child: ElevatedButton(
          child: const Text('Back to First Screen'),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
      ),
      bottomNavigationBar: const Column(
        mainAxisSize: MainAxisSize.min,
        mainAxisAlignment: MainAxisAlignment.end,
        children: [
          Center(
            child: AppodealBanner(
              adSize: AppodealBannerSize.BANNER,
            ),
          ),
        ],
      ),
    );
  }
}

ihenvyr avatar Oct 26 '23 23:10 ihenvyr

Used @Darkos-den as inspiration. (dirty solution--)

Then you just call AdAdaptiveBanner()

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:stack_appodeal_flutter/stack_appodeal_flutter.dart';

class AdAdaptiveBanner extends StatefulWidget {
  const AdAdaptiveBanner({super.key});

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

class AdAdaptiveBannerState extends State<AdAdaptiveBanner> {
  late int counter;

  @override
  void initState() {
    super.initState();
    counterBannerAd.value = counterBannerAd.value + 1;
    counter = counterBannerAd.value;
  }

  @override
  void dispose() {
    super.dispose();
    refreshBanner();
  }

  @override
  Widget build(BuildContext context) {
    return ValueListenableBuilder<int>(
      valueListenable: counterBannerAd,
      builder: (_, value, ___) {
        if (value != counter) {
          return const SizedBox();
        }
        return const AppodealBanner(adSize: AppodealBannerSize.BANNER);
      },
    );
  }
}

final ValueNotifier<int> counterBannerAd = ValueNotifier<int>(0);

void refreshBanner() async {
  await Future.delayed(const Duration(milliseconds: 50)).then((value) {
    counterBannerAd.value = counterBannerAd.value + 1;
  });
  await Future.delayed(const Duration(milliseconds: 50)).then((value) {
    counterBannerAd.value = counterBannerAd.value - 2;
  });
}

algaren avatar Aug 07 '24 21:08 algaren