admob 0.1.2 admob: ^0.1.2 copied to clipboard
A flutter plugin for admob.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:admob/admob.dart';
void main() {
runApp(new MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool _showInterstitialResponse;
bool _loadInterstitialResponse;
String APP_ID = "ca-app-pub-9929690287684724~2116069294";
String INTERSTITIAL_AD_UNIT_ID = "ca-app-pub-9929690287684724/7809349294";
String DEVICE_ID = "FF18F6CCC658F56ECA4C4623DB5082CA";
bool TESTING = true;
@override
initState() {
super.initState();
loadInterstitialAd();
}
loadInterstitialAd() async {
bool loadResponse;
try {
loadResponse = await Admob.loadInterstitial(APP_ID, INTERSTITIAL_AD_UNIT_ID, DEVICE_ID, TESTING);
} on PlatformException {
loadResponse = false;
}
setState(() {
_loadInterstitialResponse = loadResponse;
});
}
showInterstitialAd() async {
bool showResponse;
try {
showResponse = await Admob.showInterstitial;
} on PlatformException {
showResponse = false;
}
setState(() {
_showInterstitialResponse = showResponse;
});
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Plugin example app'),
),
body: new Center(child:new Text("$_loadInterstitialResponse")),
floatingActionButton: new FloatingActionButton(
onPressed: () => showInterstitialAd(),
child: new Icon(Icons.add),
),
);
}
}