Posts tagged with flutter

Flutter App. One button that leads to the 2nd page where the content is.

  • The user clicks on the button and must watch a video ad(rewarded ad).

After the video ad finishes > the user can open the 2nd page / or the 2nd page will be automatically opened when he clicks 'x' on the finished video ad.

My question is > how to do this? What would the code look like and what to use? Thank you!

I had banner, interstitial, and reward ads on one of my apps. The ads seemed to have been working for the past 2 months and then suddenly yesterday both android and iOS apps stopped showing ads:

iOS Error: code: 1, domain: com.google.admob, message: Request Error: No ad to show

Android: code: 3, domain: com.google.android.gms.ads, message: No ad config

It's also strange that both the apps have different error codes.

Package: google_mobile_ads: ^0.12.1+1

Code:

Container(      height: bannerAd.size.height.toDouble(),      child: AdWidget(             ad: bannerAd,             ),      margin: EdgeInsets.symmetric(vertical: 30), ) 

Note:

  1. The test ads seem to work just fine.
  2. The Android and iOS apps have been published on the stores and have been working just fine for the past 2 months.

I'm integrating Interstitial ads in my flutter project. But When I declare like this

 InterstitialAd? _interstitialAd; 

I am getting this error:

33:17: Error: Null safety features are disabled for this library. Try removing the package language version or setting the language version to 2.12 or higher.   InterstitialAd? _interstitialAd;                 ^ lib/admob_service.dart:64:20: Error: Null safety features are disabled for this library. Try removing the package language version or setting the language version to 2.12 or higher.     _interstitialAd!.fullScreenContentCallback = FullScreenContentCallback(                    ^ lib/admob_service.dart:79:20: Error: Null safety features are disabled for this library. Try removing the package language version or setting the language version to 2.12 or higher.     _interstitialAd!.show(); 

I saw some stackoverflow answers and tried to upgrade the sdk version from

environment:   sdk: ">=2.7.0 <3.0.0" 

to

environment:   sdk: ">=2.12.0 <3.0.0" 

Then I got errors in my whole project.The error message is :

Error: Cannot run with sound null safety, because the following dependencies don't support null safety:  - package:local_database  - package:auto_size_text  - package:queue

Is there any way other than declaring this : InterstitialAd? _interstitialAd;

I've been struggling to integrate google ads in the flutter app. It keeps crashing.

Installed version: google_mobile_ads: ^0.12.1+1

I've updated the manifest too with the ads meta-data

<meta-data             android:name="com.google.android.gms.ads.APPLICATION_ID"             android:value="<AD-CODE>" /> 

Whenever I try to debug the code on the emulator. I get these errors in the console:

Launching lib/main.dart on sdk gphone x86 arm in debug mode... ✓ Built build/app/outputs/flutter-apk/app-debug.apk. E/AndroidRuntime(23372): FATAL EXCEPTION: main E/AndroidRuntime(23372): Process: com.example.kavya_digest, PID: 23372 E/AndroidRuntime(23372): java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.IllegalStateException: E/AndroidRuntime(23372): E/AndroidRuntime(23372): ****************************************************************************** E/AndroidRuntime(23372): * Invalid application ID. Follow instructions here:                          * E/AndroidRuntime(23372): * https://googlemobileadssdk.page.link/admob-android-update-manifest         * E/AndroidRuntime(23372): * to find your app ID.                                                       * E/AndroidRuntime(23372): ****************************************************************************** E/AndroidRuntime(23372): E/AndroidRuntime(23372): E/AndroidRuntime(23372):    at android.app.ActivityThread.installProvider(ActivityThread.java:7135) E/AndroidRuntime(23372):    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6675) E/AndroidRuntime(23372):    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6592) E/AndroidRuntime(23372):    at android.app.ActivityThread.access$1300(ActivityThread.java:233) E/AndroidRuntime(23372):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1896) E/AndroidRuntime(23372):    at android.os.Handler.dispatchMessage(Handler.java:106) E/AndroidRuntime(23372):    at android.os.Looper.loop(Looper.java:223) E/AndroidRuntime(23372):    at android.app.ActivityThread.main(ActivityThread.java:7523) E/AndroidRuntime(23372):    at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(23372):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) E/AndroidRuntime(23372):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941) E/AndroidRuntime(23372): Caused by: java.lang.IllegalStateException: E/AndroidRuntime(23372): E/AndroidRuntime(23372): ****************************************************************************** E/AndroidRuntime(23372): * Invalid application ID. Follow instructions here:                          * E/AndroidRuntime(23372): * https://googlemobileadssdk.page.link/admob-android-update-manifest         * E/AndroidRuntime(23372): * to find your app ID.                                                       * E/AndroidRuntime(23372): ****************************************************************************** E/AndroidRuntime(23372): E/AndroidRuntime(23372): E/AndroidRuntime(23372):    at com.google.android.gms.internal.ads.zzzt.attachInfo(com.google.android.gms:play-services-ads-lite@@19.7.0:24) E/AndroidRuntime(23372):    at com.google.android.gms.ads.MobileAdsInitProvider.attachInfo(com.google.android.gms:play-services-ads-lite@@19.7.0:3) E/AndroidRuntime(23372):    at android.app.ActivityThread.installProvider(ActivityThread.java:7130) E/AndroidRuntime(23372):    ... 10 more Exited 

I recently integrated google_mobile_ads plugin for Flutter after firebase_admob plugin got deprecated. Ever since then my Rewarded Ads stopped working. These are the errors I get:

(13077): This request is sent from a test device. E/chromium(13077): [ERROR:cookie_manager.cc(137)] Strict Secure Cookie policy does not allow setting a secure cookie for http://googleads.g.doubleclick.net/ for apps targeting >= R. Please either use the 'https:' scheme for this URL or omit the 'Secure' directive in the cookie value. W/Ads (13077): #004 The webview is destroyed. Ignoring action.

My code is as below:

void main() {   WidgetsFlutterBinding.ensureInitialized();   MobileAds.instance.initialize();   InAppPurchaseConnection.enablePendingPurchases();   runApp(MyApp()); } class _RewardedVideoState extends State<RewardedVideo>{   bool _rewardedReady = false;   RewardedAd _rewardedAd;   static final AdRequest _adRequest = AdRequest(     keywords: <String>['Puzzles', 'Games', 'Word Games'],     nonPersonalizedAds: true,   );   @override   void didChangeDependencies() {     createRewardedAd();     super.didChangeDependencies();   }   void createRewardedAd([Score userScore]) {     print('Inside createRewardedAd');     // RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("CFA70A4A1BD59DA3323D586CA8BD2541"))     _rewardedAd = RewardedAd(       adUnitId: RewardedAd.testAdUnitId,       request: _adRequest,       listener: AdListener(           onAdLoaded: (Ad ad) {             print('${ad.runtimeType} loaded. RADHA ');             _rewardedReady = true;           },           onAdFailedToLoad: (Ad ad, LoadAdError error) {             print('${ad.runtimeType} failed to load: $error');             ad.dispose();             _rewardedAd = null;             createRewardedAd(userScore);           },           onAdOpened: (Ad ad) => print('${ad.runtimeType} onAdOpened.'),           onAdClosed: (Ad ad) {             print('${ad.runtimeType} closed.');             ad.dispose();             createRewardedAd(userScore);           },           onApplicationExit: (Ad ad) =>               print('${ad.runtimeType} onApplicationExit.'),           onRewardedAdUserEarnedReward: (RewardedAd ad, RewardItem reward) {             userScore.updateHintsEarned(reward.amount);           }),     )..load();     print('Completed RewardedAd Load ' + _rewardedAd.toString());   }   @override   void dispose() {     _rewardedAd.dispose();     super.dispose();   }   @override   Widget build(BuildContext context) {     final Score userScore = Provider.of<Score>(context, listen: false);     print('Inside RewardedVideo widget *** ........');     try {       if (_rewardedReady) {         print('Showing rewardedAd ***');         _rewardedAd.show();         _rewardedReady = false;         _rewardedAd = null;       } else         createRewardedAd(userScore);     } catch (e) {       print("error in showing ad: " + e.toString());     }     return SizedBox(       height: 0,     );   } } 

I am able to get banner ads (not included in this code) but rewarded ad does not load at all. Any idea what might be going wrong here?