googleads / googleads-mobile-flutter

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

User cannot stop rewarded ad playback #840

Closed under3415 closed 1 year ago

under3415 commented 1 year ago

Plugin Version

3.0.0

Steps to Reproduce

  1. Run flutter create bug.
  2. Update main.dart files as follows:
    
    import 'package:flutter/material.dart';
    import 'package:google_mobile_ads/google_mobile_ads.dart';

void main() { runApp(const MyApp()); }

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

// This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: const MyHomePage(title: 'Google Ads Demo'), ); } }

class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title});

final String title;

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

class _MyHomePageState extends State { RewardedAd? _rewardedAd; bool _loadingAd = false;

Future _adBuyDialog() { return showGeneralDialog( context: context, barrierDismissible: false, transitionBuilder: (context, animation, secondaryAnimation, child) { return FadeTransition( opacity: animation, child: ScaleTransition( scale: animation, child: child, ), ); }, pageBuilder: (context, animation, secondaryAnimation) { return SafeArea( child: Scaffold( backgroundColor: Colors.amber, body: ElevatedButton( style: ElevatedButton.styleFrom( backgroundColor: Colors.green, elevation: 0, minimumSize: const Size( 150, 50, )), onPressed: () async { await showRewardedAd(); if (!mounted) { return; } Navigator.pop(context); }, child: const Padding( padding: EdgeInsets.all(8.0), child: Text( "Watch Ad", style: TextStyle(color: Colors.black, fontSize: 12), ), ), ), ), ); }, ); }

Future get _createRewardedAd async { _loadingAd = true; await RewardedAd.load( adUnitId: 'ca-app-pub-3940256099942544/5224354917', //sample ads request: const AdRequest(), rewardedAdLoadCallback: RewardedAdLoadCallback( onAdLoaded: (RewardedAd ad) { _rewardedAd = ad; _loadingAd = false; }, onAdFailedToLoad: (LoadAdError error) { _rewardedAd = null; _loadingAd = false; }, )); }

Future showRewardedAd() async { int tries = 0; int maxTries = 5;

if (_rewardedAd == null) {
  while (tries < maxTries) {
    if (!_loadingAd) {
      _createRewardedAd;
    }
    await Future.delayed(const Duration(seconds: 1));

    tries++;

    if (_rewardedAd != null) {
      break;
    } else if (tries >= maxTries) {
      await showDialog(
          context: context,
          builder: (BuildContext context) {
            return AlertDialog(
              title: const Text("Ad Error"),
              content: const Text(
                  "Ad taking longer to load. Check the Internet. Continue waiting?"),
              actions: <Widget>[
                Semantics(
                  button: true,
                  label: "OK",
                  child: TextButton(
                    child: const Text("OK"),
                    onPressed: () {
                      tries = -2;
                      Navigator.of(context).pop();
                    },
                  ),
                ),
                Semantics(
                  button: true,
                  label: "Cancel",
                  child: TextButton(
                    child: const Text("Cancel"),
                    onPressed: () {
                      //remove screen scaling ban
                      Navigator.of(context).pop();
                    },
                  ),
                ),
              ],
            );
          });
    }
  }
}

if (_rewardedAd == null) {
  if (!_loadingAd) {
    _createRewardedAd;
  }

  return;
}

_rewardedAd!.fullScreenContentCallback = FullScreenContentCallback(
  onAdDismissedFullScreenContent: (RewardedAd ad) {
    ad.dispose();
    _rewardedAd = null;
  },
  onAdFailedToShowFullScreenContent: (RewardedAd ad, AdError error) async {
    ad.dispose();
    _rewardedAd = null;
    //_createRewardedAd;
  },
);
await _rewardedAd!.show(
    onUserEarnedReward: (AdWithoutView ad, RewardItem reward) {
  print("rewarded");
});

}

Future _initAds() async { await MobileAds.instance.initialize(); await _createRewardedAd; return true; }

@override Widget build(BuildContext context) { return SafeArea( child: Scaffold( appBar: AppBar( title: Text(widget.title), ), body: FutureBuilder( future: _initAds(), builder: (context, snapshot) { if (snapshot.hasData) { return const Center( child: Text( 'Click to show test ad', ), ); } else { return const Center( child: SizedBox( width: 60, height: 60, child: CircularProgressIndicator( strokeWidth: 8.0, color: Color.fromRGBO(69, 162, 158, 1.0), ), ), ); } }), floatingActionButton: FloatingActionButton( onPressed: _adBuyDialog, tooltip: 'Show Ad', child: const Icon(Icons.add), ), ), ); } }

4. Add to `Android Manifest':

<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-3940256099942544~3347511713"/>

5. Run app. Click on + button, then "watch ad" button. While the ad is playing user cannot stop it. Back button does not work. Close (X) button does not work

**Expected results:**
User can interrupt ad playback by using Android back button or clicking close button in the ad

**Actual results:** 
Ad is unstoppable 

<!-- Finally, paste the output of running `flutter doctor -v` here. -->

[√] Flutter (Channel stable, 3.10.0, on Microsoft Windows [Version 10.0.19045.2965], locale en-US) • Flutter version 3.10.0 on channel stable at C:\src\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 84a1e904f4 (2 days ago), 2023-05-09 07:41:44 -0700 • Engine revision d44b5a94c9 • Dart version 3.0.0 • DevTools version 2.23.1

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.2) • Android SDK at C:\Users\user\AppData\Local\Android\sdk • Platform android-33, build-tools 33.0.2 • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
• Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694) • All Android licenses accepted.

[√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[!] Visual Studio - develop for Windows (Visual Studio Community 2022 17.5.5) • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community • Visual Studio Community 2022 version 17.5.33627.172 • Windows 10 SDK version 10.0.22621.0 X Visual Studio is missing necessary components. Please re-run the Visual Studio installer for the "Desktop development with C++" workload, and include these components: MSVC v142 - VS 2019 C++ x64/x86 build tools

[√] Android Studio (version 2022.2) • Android Studio at C:\Program Files\Android\Android Studio • 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 17.0.6+0-b2043.56-9586694)

[√] VS Code (version 1.78.1) • VS Code at C:\Users\user\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.64.0

[√] Connected device (3 available) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19045.2965] • Chrome (web) • chrome • web-javascript • Google Chrome 113.0.5672.93 • Edge (web) • edge • web-javascript • Microsoft Edge 113.0.1774.35

[√] Network resources • All expected network resources are available.



</details>
huycozy commented 1 year ago

Hi @under3415 There was a similar issue here as well. It looks like an issue from ads library rather than this Flutter ads plugin since I also see the issue with Android native reward sample code (you can try it to check this).

Also, I see there is a related issue that you can take a look on it: https://groups.google.com/g/google-admob-ads-sdk/c/4BGujai2Cig/m/3t2tuJmfBgAJ

under3415 commented 1 year ago

We can close it if it is not a flutter issue. There is no related issue that is in progress though. This whole system of bug reporting is starting to feel like an exercise in stalling and finger pointing, very unproductive. I thought ads were Google's number one priority, it is their bread and butter, it is surprising how little they seem to care! :-D

huycozy commented 1 year ago

I watch some rewarded ads recently on apps/games and see it also can not be closed until it finished (even pressing back button or close button on the top corner). So I think it could be a change with ads activity that's out of the scope of this flutter plugin.

I will close this issue from here. If you disagree, please write in the comments and I will reopen it. Thanks!

under3415 commented 1 year ago

OK to close it. Is there somewhere else I could file this bug for the Google ads team?

huycozy commented 1 year ago

You can try opening a new conversation at https://groups.google.com/g/google-admob-ads-sdk