admob_interface 0.0.2 admob_interface: ^0.0.2 copied to clipboard
A new Flutter project.
import 'package:admob_interface/admob_interface.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
final adMobAd = AdMobAd();
AdManager().init(
adMobAd,
(tag) {
if (tag == '激励测试') return 'ca-app-pub-3940256099942544/5224354917';
if (tag == '插页测试') return 'ca-app-pub-3940256099942544/1033173712';
return '';
},
preloadAds: {
AdType.rewardedVideo: ['激励测试'],
AdType.interstitial: ['插页测试'],
},
);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
CupertinoButton(
child: const Text('激励视频测试'),
onPressed: () {
AdManager().showAd('激励测试', AdType.rewardedVideo);
},
),
CupertinoButton(
child: const Text('插页测试'),
onPressed: () {
AdManager().showAd('插页测试', AdType.interstitial);
},
),
CupertinoButton(
child: const Text('测试面板'),
onPressed: () {
GoogleAdMob.mediationTestSuite();
},
),
],
),
),
),
);
}
}