gpt4 book ai didi

android - flutter - 原生广告不会加载和显示,它的事件回调也不会显示任何内容

转载 作者:行者123 更新时间:2023-11-29 02:18:35 28 4
gpt4 key购买 nike

在等待官方 Admob 的 Native Ads 时,我尝试使用第 3 方插件将其集成。

我尝试使用一个声称可以显示 Admob 原生广告 的插件 here .

但是,原生广告不会在 Android 设备上加载和显示(iOS 尚未测试)。

事件回调 也没有显示任何内容。

我已经提交了一个问题 here ,不过我觉得作者可能很忙,所以我也在这里发帖。

下面是我的代码:

对于初始化:

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();
...
}

NativeAds 展示位置在以下结构中:

@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"),
),
),

...

...


有什么想法吗?

提前致谢...

==更新(根据 Itiel Maimon 的建议)

我在 runApp() 之前在 main.dart 中进行了初始化,但在调试中出现了以下错误:

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)

有什么解决办法吗?

最佳答案

不要将 NativeAds.initialize(); 放在 initState() 方法上。把它放在调用 runApp() 之前。例如 void main() {
NativeAds.initialize();
运行应用程序(我的应用程序());
}

还要确保您使用的是 Admob test ad unit ids ,否则您将看不到任何广告。

如果仍然无法正常工作,请尝试使用 NativeAdViewWrapper通过在请求的位置使用 child: const NativeAdViewWrapper(),

关于android - flutter - 原生广告不会加载和显示,它的事件回调也不会显示任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58010650/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com