Maximizing Revenue: A Comprehensive Guide to Integrating and Showcasing Google AdMob Banner Ads in Our Flutter Mobile Application

Purvik Rana
6 min readApr 13, 2024

In today’s digital age, mobile applications have become an integral part of our daily lives. Whether it’s for entertainment, productivity, or connecting with others, mobile apps offer endless possibilities. However, for developers, creating a successful app goes beyond just coding functionality; it also involves generating revenue to sustain and grow their projects.

One of the most popular and effective ways to monetize mobile applications is through advertisements. And when it comes to mobile ad networks, Google AdMob stands out as a powerhouse, offering developers a vast array of advertising solutions to maximize their earnings.

As a Flutter developer, if we’re looking to monetize our mobile app efficiently, integrating Google AdMob ads is a strategic move. Flutter’s versatility and Google AdMob’s robustness make them a perfect match for developers aiming to monetize their apps while providing a seamless user experience.

In this comprehensive guide, we’ll delve into the process of integrating and showcasing Google AdMob ads in our Flutter mobile application. From setting up our AdMob account to implementing ads seamlessly into our app’s UI, we’ll cover everything you need to know to start earning revenue from your Flutter app. So, let’s dive in and unlock the potential of mobile advertising with Google AdMob and Flutter.

Why Google Admob?

Before we dive into the integration process, let’s understand why Google AdMob is the preferred choice for many developers.

  1. Large Advertiser Base: Google AdMob connects developers with millions of advertisers worldwide, ensuring a steady stream of high-quality ads to display in our app.
  2. Robust Analytics: AdMob provides comprehensive analytics and reporting tools, allowing us to track ad performance, user engagement, and revenue in real-time.
  3. Flexible Ad Formats: AdMob offers various ad formats, including banner ads, interstitial ads, rewarded ads, and native ads, giving us the flexibility to choose the best-suited format for our app.
  4. High Revenue Potential: With Google’s vast network of advertisers and advanced targeting capabilities, AdMob offers competitive eCPMs (effective cost per thousand impressions), maximizing our revenue potential.

Getting Started with Google AdMob

Before integrating AdMob ads into our Flutter app, we’ll need to set up an AdMob account and create ad units.

  • Sign Up for AdMob: Visit the Google AdMob website and sign up for an account using our Google credentials. If we already have a Google account, we can use it to log in.
  • Create Apps: Once logged in, navigate to the “Apps” tab and click on “Add App” to register our Flutter app. Follow the prompts to provide the necessary details about our app. Create individual apps for iOS and Android both.
Google Admob screen displaying how to add new app on it
Adding an App on Google AdMob
  • Create Ad Units: After registering our app, click on the “Ad units” tab and select “Add ad unit” to create new ad units. Choose the ad format (banner, interstitial, rewarded, etc.) and provide relevant details. Make sure to note down ad unit ID for each individual ad units.
Adding ad unit inside an App on Google AdMob

For only Testing purpose we don’t require to configure next step, however once application is ready to roll out into Production this will be required.

  • Set Up Payment Details: Before our ads go live, we’ll need to set up payment details to receive our earnings. Navigate to the “Payments” tab and follow the prompts to add our payment information.

Integrating AdMob Ads into Our Flutter App

Now that we’ve set up our AdMob account and created ad units, let’s proceed with integrating ads into your Flutter app using the google_mobile_ads package.

  • Add google_mobile_ads Package: Create new flutter project or open exisiting one in any preferred code editor (my preferred choice is vs code) and add the google_mobile_ads package to our project's pubspec.yaml file.
dependencies:
flutter:
sdk: flutter
google_mobile_ads: ^4.0.0
  • Initialize AdMob: In our Flutter app’s main file (usually main.dart), initialize AdMob by adding the following code:
void main() {
WidgetsFlutterBinding.ensureInitialized();
MobileAds.instance.initialize();
runApp(const AppHome());
}

Display Banner Ads

To display banner ads in our app, we can use the BannerAd widget provided by the google_mobile_ads package. Place the BannerAd widget within our app's layout wherever we want the banner ad to appear.

  • Create Adhelper class to hold all ad unit IDs: We’ll be creating an AdHelper class which will hold all the information about Ad Unit IDs and will return it based on platform (iOS or Android).
import 'dart:io';

class AdHelper {
static String get bannerAdUnitId {
if (Platform.isAndroid) {
return 'ca-app-pub-3940256099942544/6300978111'; // Test Ad ID
// return ''; // Add Actual Ad ID for Production
} else if (Platform.isIOS) {
return 'ca-app-pub-3940256099942544/2934735716'; // Test Ad ID
// return ''; // Add Actual Ad ID for Production
} else {
throw UnsupportedError('Unsupported platform');
}
}
}
  • Initialize a parameter and load banner ad: Declare a parameter of BannerAd class _bannerAd load advertisement and assign it to this parameter in initState() method as showcased below.
class _MainAppState extends State<MainApp> {
BannerAd? _bannerAd;
...

@override
void initState() {
super.initState();
BannerAd(
adUnitId: AdHelper.bannerAdUnitId,
request: const AdRequest(),
size: AdSize.banner,
listener: BannerAdListener(
onAdLoaded: (ad) {
setState(() {
_bannerAd = ad as BannerAd;
});
},
onAdFailedToLoad: (ad, err) {
print('Failed to load a banner ad: ${err.message}');
ad.dispose();
},
),
).load();

...
}
}
  • Display Banner Ad on the screen: Once ad has been loaded we can null check _bannerAd parameter and show case BannerAd as shown below on bottom of the screen.
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Developer Purvik'),
),
body: SafeArea(
child: Stack(
children: [
Center(
child: Text(
'Flutter AdMob\nGuide',
style: Theme.of(context).textTheme.headlineLarge,
textAlign: TextAlign.center,
),
),
if (_bannerAd != null)
Align(
alignment: Alignment.bottomCenter,
child: SizedBox(
width: _bannerAd!.size.width.toDouble(),
height: _bannerAd!.size.height.toDouble(),
child: AdWidget(ad: _bannerAd!),
),
),
],
),
),
);
}
  • End Result: Now simply run the application on simulator and see the result. We’ll be able to see Banner Ads getting loaded on screen as show below.
A screen shot of Flutter Mobile App Screen displaying Google Banner Ads loaded at the bottom

At the end

Integrating Google AdMob ads into our Flutter mobile application can significantly boost our revenue while providing users with relevant and engaging advertisements. By following the steps outlined in this guide, we can seamlessly integrate AdMob ads into our app and start monetizing our Flutter projects effectively to show case Banner Ads.

Remember to continuously monitor ad performance and user feedback to optimize our ad strategy and maximize our earnings. With the power of Flutter and Google AdMob combined, we’re well-equipped to create a successful and profitable mobile app. In my upcoming guide, we’ll go through How we can integrate and display Interstitial and Rewarded Ads in our Flutter made Mobile Application.

In case, anyone good to learn this by watching video checkout youtube tutorial as well.

Do claps if this article has given any new information today and have ☮️. Follow here to have more future updates and connect with me on,

--

--

Purvik Rana

Flutter Tech Lead, Adventure Lover, Mountain Trekker & much more. Love to share knowledge about stuffs I've experienced.