I am using Flutter, and trying to build an app using app open ad(by google admob) and Future Builder. Because future builder takes long, I want to keep the ad displayed for longer than 5 seconds, or close the ad after future builder gets data. I have already implemented both admob, and future builder.
The relationship between openApp ad and FutureBuilder
Could you teach me how to change the duration to show ad?
If you want more information to answer this, please let me know. Thanks!
code:
AppOpenAd? openAd;
Future<void> loadInitialAd()async{
await AppOpenAd.load(
adUnitId: AdHelper.startAppAdUnitId,
request: const AdRequest(),
adLoadCallback: AppOpenAdLoadCallback(
onAdLoaded: (ad){
print("Ad is loaded");
openAd = ad;
openAd!.show();
},
onAdFailedToLoad: (error){
print("ad failed to load ${error}");
}
), orientation: AppOpenAd.orientationPortrait
);
}
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await MobileAds.instance.initialize();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return
return MaterialApp(
home:MyHomePage());
);
}
}
class MyHomePage extends StatefulWidget {
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: FutureBuilder<List<MonumentModel>>(
future: MonumentModel.fetchMonument(),
builder: (context, snapshot) {
return
snapshot.hasData ? Container(child: Widget(snapshot!.data))
: SizedBox(child: Center(child: CircularProgressIndicator())),
Without seeing the code it is difficult to help you, but did you check the documentation? Reading the docs, it seems that the ad is not automatically dismissed, which tells me that most likely your ad is dismissed by something else. Probably a navigation event that is used to show your loading screen.
Check the FullScreenContentCallback
declaration to see how the ad should be shown and dismissed.