appodeal / Appodeal-Flutter-Plugin

Official Flutter Plugin that adds Appodeal SDK support to your Flutter application.
https://pub.dev/packages/stack_appodeal_flutter
Apache License 2.0
20 stars 3 forks source link

Banner view content not displayed after back navigation #10

Open Darkos-den opened 2 years ago

Darkos-den commented 2 years ago

Steps for reproducing:

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

da2gl commented 2 years ago

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

da2gl commented 2 years ago

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

marcos93net commented 2 years ago

Same problem.. Any solution?

Darkos-den commented 2 years ago

@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 commented 2 years ago

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.

phamanhminh1208 commented 1 year ago

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

da2gl commented 1 year ago

@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.

ihenvyr commented 11 months ago

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,
            ),
          ),
        ],
      ),
    );
  }
}
algaren commented 2 months ago

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;
  });
}