admob_flutter
a flutter plugin that uses native platform views to show admob banner ads!
this plugin also has support for interstitial and reward ads.
installation
- add this to your package’s pubspec.yaml file:
dependencies:
admob_flutter: "<latest_version>"
- install it – you can install packages from the command line:
flutter pub get
android specific setup
update your androidmanifest.xml
add your admob app id to your app’s androidmanifest.xml file by adding the <meta-data>
tag shown below. you can find your app id in the admob ui. for android:value insert your own admob app id in quotes, as shown below.
you can use these test app id’s from admob for development:
android: ca-app-pub-3940256099942544~3347511713
ios: ca-app-pub-3940256099942544~1458002511
<manifest>
<application>
<meta-data
android:name="com.google.android.gms.ads.application_id"
android:value="ca-app-pub-3940256099942544~3347511713"/>
</application>
</manifest>
ios specific setup
update your info.plist
per firebase instructions.
<key>gadapplicationidentifier</key>
<string>ca-app-pub-3940256099942544~1458002511</string>
and add
<key>io.flutter.embedded_views_preview</key>
<true/>
starting from beta 6, you also need to display the app tracking transparency authorization request for accessing the idfa,
so you have to update your info.plist
to add the nsusertrackingusagedescription
key with a custom message describing your usage.
below is an example description text:
<key>nsusertrackingusagedescription</key>
<string>this identifier will be used to deliver personalized ads to you.</string>
see prepare for ios 14+ for more information.
you also need to update your ios/podfile
by adding platform :ios, '9.0'
at the very top of your file.
initialize the plugin
first thing to do before attempting to show any ads is to initialize the plugin. you can do this in the earliest starting point of your app, your main
function:
import 'package:admob_flutter/admob_flutter.dart';
void main() {
widgetsflutterbinding.ensureinitialized();
// initialize without device test ids.
admob.initialize();
// or add a list of test ids.
// admob.initialize(testdeviceids: ['your device id']);
}
if you’re using ios, you may also need to request the tracking authorization in order to display personalized ads:
// run this before displaying any ad.
await admob.requesttrackingauthorization();
supported platforms
0.3.0
>= ios0.2.0
>= androidx
supported admob features
- banner ads
- interstitial ads
- reward ads
- native ads (coming soon)
Comments are closed.