2

While waiting for official Admob's Native Ads for a flutter, I try to integrate it using 3rd party plugin.

I try using a plugin that claimed can show Admob's Native Ads here.

However, the native ads wont load & show on Android Devices (iOS not yet tested).

The event callback also not showing anything.

I have submitted an issue here, but I think the author may be busy, so I post also here.

Below are my codes:

For Initialization:

class HomeScreen extends StatefulWidget{
  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> with AfterLayoutMixin<HomeScreen> {

  @override
    void initState() {
      // TODO: implement initState
      super.initState();      
      NativeAds.initialize();
      ...
    }

For NativeAds placement is under below structures:

@override
Widget build(BuildContext context) {
  return Stack(
    children: <Widget>[
      Scaffold(
        appBar: AppBar( .. ),
        body: OfflineBuilder(
              connectivityBuilder: (BuildContext context, ConnectivityResult connectivity, Widget child) {
                  ...  
                  child: NestedScrollView(
                      headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) { ... }
                      body: RefreshIndicator(
                        backgroundColor: Pigment.fromString(UIData.primaryColor),
                        color: Colors.white,
                        onRefresh: () => homeBloc.init(),
                        child: ListView(
                          children: <Widget>[
                            Row(
                            ...
                              ListView(
                                physics: NeverScrollableScrollPhysics(),
                                shrinkWrap: true,
                                children: <Widget>[

                                ...


                                SizedBox(
                                  width: double.infinity,
                                  height: 320,
                                  child: NativeAdView(
                                    onParentViewCreated: (_) {
                                      print("sinative create.....");
                                    },
                                    androidParam: AndroidParam()
                                      ..placementId = "ca-app-pub-xxx" //my admob
                                      ..packageName = "com.apps.myapp"
                                      ..layoutName = "native_ad_layout"
                                      ..attributionText = "AD",
                                    iosParam: IOSParam()
                                      ..placementId = "ca-app-pub-3940256099942544/3986624511" // test
                                      ..bundleId = "{{YOUR_IOS_APP_BUNDLE_ID}}"
                                      ..layoutName = "{{YOUR_CREATED_LAYOUT_FILE_NAME}}"
                                      ..attributionText = "SPONSORED",
                                    onAdImpression: () => print("native is show"),
                                    onAdClicked: () => print("onAdClicked!!!"),
                                    onAdFailedToLoad: (Map<String, dynamic> error) => print("native is error ==> $error"),
                                  ),
                                ),                      

                                ...

                                ...


Any Idea?

Thanks In Advance...

==Update (After Itiel Maimon's suggestion)

I have place initialization in main.dart before runApp(), but in debug i got below error:

E/flutter (10737): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: MissingPluginException(No implementation found for method initialize on channel native_ads)
E/flutter (10737): #0      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:314:7)
E/flutter (10737): <asynchronous suspension>
E/flutter (10737): #1      new NativeAds.initialize (package:native_ads/native_ads.dart:5:14)
E/flutter (10737): #2      main.<anonymous closure> (package:apps789apps/main.dart:35:15)
E/flutter (10737): #3      _rootRunUnary (dart:async/zone.dart:1132:38)
E/flutter (10737): #4      _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter (10737): #5      _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
E/flutter (10737): #6      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
E/flutter (10737): #7      Future._propagateToListeners (dart:async/future_impl.dart:707:32)
E/flutter (10737): #8      Future._completeWithValue (dart:async/future_impl.dart:522:5)
E/flutter (10737): #9      _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:30:15)
E/flutter (10737): #10     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:288:13)
E/flutter (10737): #11     SystemChrome.setPreferredOrientations (package:flutter/src/services/system_chrome.dart)
E/flutter (10737): <asynchronous suspension>
E/flutter (10737): #12     main (package:apps789apps/main.dart:31:16)
E/flutter (10737): <asynchronous suspension>
E/flutter (10737): #13     _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:229:25)
E/flutter (10737): #14     _rootRun (dart:async/zone.dart:1124:13)
E/flutter (10737): #15     _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter (10737): #16     _runZoned (dart:async/zone.dart:1516:10)
E/flutter (10737): #17     runZoned (dart:async/zone.dart:1500:12)
E/flutter (10737): #18     _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:221:5)
E/flutter (10737): #19     _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:305:19)
E/flutter (10737): #20     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)

any idea to solve ?

questionasker
  • 2,536
  • 12
  • 55
  • 119

3 Answers3

0

Don't put the NativeAds.initialize(); on the initState() method. Put it before you call runApp(). e.g void main() { NativeAds.initialize(); runApp(MyApp()); }

Also make sure you are using Admob test ad unit ids, otherwise you will not see any ads.

If it still isn't working, try to use the NativeAdViewWrapper by using child: const NativeAdViewWrapper(), at the requested place.

Itiel Maimon
  • 834
  • 2
  • 9
  • 26
  • i have followed all of your suggestion, but now get an error `MissingPluginException(No implementation found for method initialize on channel native_ads` (please see my updated question). thanks... – questionasker Sep 28 '19 at 04:16
0

I recommend you to use this plugin flutter_native_admob, I am using in some of my apps and it's pretty good and easy.

// Initialize using you APPID
NativeAdmob().initialize(appID: APP_ID);

// Show the Native Ad Widget inside your list/grid..
NativeAdmobBannerView(
            adUnitID: Ads.NATIVE_ID,
            style: BannerStyle.light,
            showMedia: true,
          ) 
djalmafreestyler
  • 1,703
  • 5
  • 21
  • 42
0

https://pub.dev/packages/native_ads

A new Package for Native Ads available. Try this.

Supported native ads fields

  1. Headline(Required)
  2. Body(Required)
  3. Call To Action(Required)
  4. Ad Attribution(Required)
  5. Media
  6. Icon
  7. Star
  8. rating
  9. Store
  10. Price
  11. Advertiser

Event callback

Receive callbacks for some events by passing to the NativeAdView constructor

  1. onAdImpression
  2. onAdClicked
  3. onAdFailedToLoad
  4. onAdLeftApplication
  5. onAdLoaded

Right now No support Mediation Ads. Check the official link given above for new features

Mithun S
  • 408
  • 8
  • 20