Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

    1. flutter native ads

flutter plugin for admob native ads. compatible with android and ios using platformview.

android ios
native ads image

getting started

android

admob 17 requires the app id to be included in the androidmanifest.xml. failure
to do so will result in a crash on launch of your app. the line should look like:

<meta-data
    android:name="com.google.android.gms.ads.application_id"
    android:value="[admob_app_id]"/>

where [admob_app_id] is your app id. you must pass the same value when you
initialize the plugin in your dart code.

ios

admob 7.42.0 requires the app id to be included in info.plist. failure to do so will result in a crash on launch of your app. the lines should look like:

<key>gadapplicationidentifier</key>
<string>[admob_app_id]</string>

where [admob_app_id] is your app id. you must pass the same value when you initialize the plugin in your dart code.

and platformview

<key>io.flutter.embedded_views_preview</key>
<true/>

layout

this plugin supported custom layout

android

you can use anything if the parent is a viewgroup.
the example uses relativelayout.

use com.google.android.gms.ads.formats.unifiednativeadview for the parent.

image

use com.google.android.gms.ads.formats.mediaview for mediaview.

image

  • xml
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.gms.ads.formats.unifiednativeadview 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/flutter_native_ad_unified_native_ad"
    ...
    
    <!-- viewgroup -->
    <relativelayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        
        ...

        <com.google.android.gms.ads.formats.mediaview
            android:id="@+id/flutter_native_ad_media"
            ...

example

ios

please set gadunifiednativeadview for the parent.

image

please set gadmediaview to mediaview.

image

please set restoration id for view that displays attribution

image

example

mapping native ads to layout

need to mapping the view

android

mapping by view id

view id
unifiednativeadview flutter_native_ad_unified_native_ad
headline flutter_native_ad_headline
body flutter_native_ad_body
mediaview flutter_native_ad_media
call to action flutter_native_ad_call_to_action
attribution flutter_native_ad_attribution

ios

mapping by outlet

image

usage

import 'package:flutter/material.dart';
import 'package:native_ads/native_ad_param.dart';
import 'package:native_ads/native_ad_view.dart';

import 'package:native_ads/native_ads.dart';

void main() {
  nativeads.initialize();
  runapp(myapp());
}

class myapp extends statelesswidget {
  @override
  widget build(buildcontext context) {
    return materialapp(
      home: scaffold(
        appbar: appbar(
          title: const text('nativeads example app'),
        ),
        body: center(
          child: listview.separated(
            itembuilder: (context, index) {
              if (index % 10 == 0) {
                return padding(
                  padding: const edgeinsets.all(8.0),
                  child: sizedbox(
                    width: double.infinity,
                    height: 320,
                    child: nativeadview(
                      onparentviewcreated: (_) {
                      },
                      androidparam: androidparam()
                        ..placementid = "ca-app-pub-3940256099942544/2247696110" // test
                        ..packagename = "sakebook.github.com.native_ads_example"
                        ..layoutname = "native_ad_layout"
                        ..attributiontext = "ad",
                      iosparam: iosparam()
                        ..placementid = "ca-app-pub-3940256099942544/3986624511" // test
                        ..bundleid = "sakebook.github.com.nativeadsexample"
                        ..layoutname = "unifiednativeadview"
                        ..attributiontext = "sponsored",
                      onadimpression: () => print("onadimpression!!!"),
                      onadclicked: () => print("onadclicked!!!"),
                      onadfailedtoload: (map<string, dynamic> error) => print("onadfailedtoload!!! $error"),
                    ),
                  ),
                );
              } else {
                return padding(
                  padding: const edgeinsets.all(8.0),
                  child: text(
                    "this is text $index",
                    style: theme.of(context).texttheme.body1,
                  ),
                );
              }
            },
            itemcount: 50,
            separatorbuilder: (context, _) => const divider(),
          ),
        ),
      ),
    );
  }
}

supported native ads fields

  • headline
  • body
  • media
  • call to action
  • ad attribution

event callback

receive callbacks for some events by passing to the nativeadview constructor

  • onadimpression
  • onadclicked
  • onadfailedtoload
  • onadleftapplication
  • onadloaded

Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Comments are closed.