pub package

flutter_native_admob

Plugin to integrate Firebase Native Admob to Flutter application

Warning: The plugin is based on Flutter PlatformView (AndroidView) to create a custom widget from Native View. Therefore, only Android is supported at the moment. For iOS, wait for Flutter team to implement iOSView equivalent.

Getting Started

For help getting started with Flutter, view our online documentation.

How it works

The plugin provides:

  • NativeAdmob: a singleton class that let you to initialize Admob app ID
  • NativeAdmobBannerView: a Flutter widget

Initialize Admob app ID

NativeAdmob allows you to initialize Admob ID. For example:

final _nativeAdmob = NativeAdmob();

@override
void initState() {
super.initState();

_nativeAdmob.initialize(appID: "<Your Admob app ID>");
}

Integrate banner view widget

'NativeAdmobBannerView' is a Flutter widget, so you can add it anywhere in Flutter application. For example:

@override
Widget build(BuildContext context) {
return MaterialApp(
  home: Scaffold(
    appBar: AppBar(
      title: const Text('Plugin example app'),
    ),
    body: ListView(
      children: <Widget>[
        Container(
          margin: EdgeInsets.only(bottom: 20.0),
          height: 200.0,
          color: Colors.green,
        ),
        Container(
          margin: EdgeInsets.only(bottom: 20.0),
          height: 200.0,
          color: Colors.green,
        ),
        Container(
          margin: EdgeInsets.only(bottom: 20.0),
          height: 200.0,
          color: Colors.green,
        ),
        NativeAdmobBannerView(
          adUnitID: "<Your ad unit ID>",
          style: BannerStyle.dark, // enum dark or light
          showMedia: true, // whether to show media view or not
          contentPadding: EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 0.0), // content padding
        ),
        Container(
          margin: EdgeInsets.only(bottom: 20.0),
          height: 200.0,
          color: Colors.green,
        ),
        Container(
          margin: EdgeInsets.only(bottom: 20.0),
          height: 200.0,
          color: Colors.green,
        ),
        Container(
          margin: EdgeInsets.only(bottom: 20.0),
          height: 200.0,
          color: Colors.green,
        ),
      ],
    ),
  ),
);
}

Warning: NativeAdmobBannerView has a fixed height. Its height is based on content height, content padding (contentPadding parameter) and media view (showMedia parameter). So you don't need to worry about the widget height.

Example

To run example project, please follow this link: Flutter Firebase to integrate you google services

Libraries

flutter_native_admob

Dart

dart:ui
Built-in types and core primitives for a Flutter application. [...]

Core

dart:async
Support for asynchronous programming, with classes such as Future and Stream. [...]
dart:collection
Classes and utilities that supplement the collection support in dart:core. [...]
dart:convert
Encoders and decoders for converting between different data representations, including JSON and UTF-8. [...]
dart:core
Built-in types, collections, and other core functionality for every Dart program. [...]
dart:developer
Interact with developer tools such as the debugger and inspector. [...]
dart:math
Mathematical constants and functions, plus a random number generator. [...]
dart:typed_data
Lists that efficiently handle fixed sized data (for example, unsigned 8 byte integers) and SIMD numeric types. [...]

VM

dart:io
File, socket, HTTP, and other I/O support for non-web applications. [...]
dart:isolate
Concurrent programming using isolates: independent workers that are similar to threads but don't share memory, communicating only via messages. [...]