搜尋套件、儲存庫與 APP 分類

套件詳情v0.5.0

native_ads

AdMob 原生廣告的 Flutter 插件。使用 PlatformView 兼容 Android 和 iOS。

近 30 天下載
24
喜歡數
42
Pub 分數
40

安裝套件

flutter pub add native_ads

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 插件,可將 AdMob 原生廣告整合至 Android 與 iOS 平台的行動應用程式中。利用 PlatformView,它提供了一種無縫的方式來顯示豐富且可自訂的廣告內容,使其與應用程式的設計相符。該插件簡化了載入與呈現原生廣告的過程,無需撰寫平台特定程式碼。對於希望以高參與度廣告格式來 monetize 應用程式,同時維持一致使用者體驗的開發者而言,這是一個理想選擇。

適用情境

  • 透過原生廣告單元 monetizing 移動應用
  • 在應用資訊流中顯示視覺上整合的廣告
  • 透過豐富媒體廣告提升使用者參與度
  • 使用單一程式碼庫同時支援 Android 和 iOS
  • 自定義廣告外觀以匹配應用 UI

主要特色

  • 基於 PlatformView 的實作
  • AdMob 兼容性
  • 跨平台支援(Android 與 iOS)
  • 富媒體廣告渲染
  • 透過 Flutter pub 实現輕鬆整合
  • 可自定義的廣告範本

適合對象

  • 尋求原生廣告整合的 Flutter 開發者
  • 需要高品質廣告投放的應用
  • 同時針對 Android 和 iOS 的專案
  • 專注於使用者體驗一致性的開發人員
  • 以變現為重點的移動應用團隊

使用建議

  • 需要 AdMob 帳戶和設定
  • 依賴於 Google 移動廣告 SDK
  • 可能需要額外設定以自訂廣告
  • 僅限AdMob作為後端提供方
  • 性能取決於網路和裝置功能

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

flutter_native_ads

version

Flutter plugin for AdMob Native Ads. Compatible with Android and iOS using PlatformView.

Android iOS
image 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. You need to create a layout file.

Android

You can use anything if the parent is a ViewGroup. The example uses ConstraintLayout.

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 -->
    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/relativeLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        
        ...

        <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
Call To Action flutter_native_ad_call_to_action
Attribution flutter_native_ad_attribution
MediaView flutter_native_ad_media
Icon flutter_naitve_ad_icon
Star rating flutter_naitve_ad_star
Store flutter_naitve_ad_store
Price flutter_naitve_ad_price
Advertiser flutter_naitve_ad_advertiser
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() {
  WidgetsFlutterBinding.ensureInitialized();
  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 = "{{YOUR_ANDROID_APP_PACKAGE_NAME}}"
                        ..layoutName = "{{YOUR_CREATED_LAYOUT_FILE_NAME}}"
                        ..attributionText = "AD"
                        ..testDevices = ["{{YOUR_TEST_DEVICE_IDS}}"],
                      iosParam: IOSParam()
                        ..placementId = "ca-app-pub-3940256099942544/3986624511" // test
                        ..bundleId = "{{YOUR_IOS_APP_BUNDLE_ID}}"
                        ..layoutName = "{{YOUR_CREATED_LAYOUT_FILE_NAME}}"
                        ..attributionText = "SPONSORED"
                        ..testDevices = ["{{YOUR_TEST_DEVICE_IDS}}"],
                      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(Required)
  • Body(Required)
  • Call To Action(Required)
  • Ad Attribution(Required)
  • Media
  • Icon
  • Star rating
  • Store
  • Price
  • Advertiser

Event callback

Receive callbacks for some events by passing to the NativeAdView constructor

  • onAdImpression
  • onAdClicked
  • onAdFailedToLoad
  • onAdLeftApplication
  • onAdLoaded

Reference

Limitations

This is just an initial version of the plugin. There are still some limitations:

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。