-
-
Notifications
You must be signed in to change notification settings - Fork 58
Initialize
Before creating any ads, you must initalize the admob. It can be initialized only once:
import 'package:flutter/foundation.dart';
String get nativeUnitId {
/// Always test with test ads
if (kDebugMode)
return MobileAds.nativeAdTestUnitId;
else return 'your-native-ad-unit-id';
}
String get bannerUnitId {
/// Always test with test ads
if (kDebugmode)
return MobileAds.bannerAdTestUnitId;
else return 'you-banner-ad-unit-id';
}
void main() {
// Add this line if you will initialize it before runApp
WidgetsFlutterBinding.ensureInitialized();
MobileAds.initialize(
nativeAdUnitId: nativeAdUnitId,
bannerAdUnitId: bannerAdUnitId,
);
runApp(MyApp());
}
❗NOTE:❗ Unit IDs are NOT
App IDs
When building and testing your apps, make sure you use test ads rather than live, production ads. Failure to do so can lead to suspension of your account.
Test Ids:
-
App ID:
ca-app-pub-3940256099942544~3347511713
-
Native Unit ID:
ca-app-pub-3940256099942544/2247696110
Next: Creating a native ad -
Banner Unit ID:
ca-app-pub-3940256099942544/6300978111
Next: Creating a banner ad
They've been specially configured to return test ads for every request, and you're free to use it in your own apps while coding, testing, and debugging. Just make sure you replace it with your own ad unit ID before publishing your app.
For more information about how the Mobile Ads SDK's test ads work, see Test Ads.