How to open another page after rewarded ad is watched in 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!
Use the following code on your first page above the build method
late RewardedAd _rewardedAd; bool _isRewardedAdReady = false; // TODO: Implement _loadRewardedAd() void _loadRewardedAd() { RewardedAd.load( adUnitId: AdHelper.rewardedAdUnitId, request: AdRequest(), rewardedAdLoadCallback: RewardedAdLoadCallback( onAdLoaded: (ad) { this._rewardedAd = ad; ad.fullScreenContentCallback = FullScreenContentCallback( onAdDismissedFullScreenContent: (ad) { setState(() { _isRewardedAdReady = false; }); _loadRewardedAd(); }, ); setState(() { _isRewardedAdReady = true; }); }, onAdFailedToLoad: (err) { print('Failed to load a rewarded ad: ${err.message}'); setState(() { _isRewardedAdReady = false; }); }, ), ); }After that initialize and dispose the rewardedad like
@override void initState() { _loadRewardedAd(); super.initState(); } @override void dispose() { _rewardedAd.dispose(); super.dispose(); }Now call the rewarede ad with Navigating to othe page
GestureDetector( onTap: () { if(_isRewardedAdReady){ _rewardedAd.show(onUserEarnedReward: (RewardedAd ad, RewardItem reward) { print( '$ad with reward $RewardItem(${reward.amount}, ${reward.type}'); }); } Navigator.pushReplacement( context, MaterialPageRoute(builder: (context)=>SecondPage())); }, child: CustomButton(text:'GoTo Second Page') ),for better understand go to here