我正在使用这个插件
\n这个插件中Admob的factoryId是什么..
\n我在哪里可以获得 admob 广告的factoryId?
\n因为当我尝试调用原生广告时我收到此错误
\nE/flutter (19354): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: PlatformException(NativeAdError, Can\'t find NativeAdFactory with id: FLTGoogleMobileAdsPlugin, null, null)\nE/flutter (19354): #0 StandardMethodCodec.decodeEnvelope\npackage:flutter/\xe2\x80\xa6/services/message_codecs.dart:581\nE/flutter (19354): #1 MethodChannel._invokeMethod\npackage:flutter/\xe2\x80\xa6/services/platform_channel.dart:158\nE/flutter (19354): <asynchronous suspension>\nE/flutter (19354): #2 NativeAd.load\npackage:google_mobile_ads/src/ad_containers.dart:576\nE/flutter (19354): <asynchronous suspension>\nE/flutter (19354):\nRun Code Online (Sandbox Code Playgroud)\n这是我的原生广告类
\n\nclass NativeAdWidget extends StatefulWidget {\n @override\n State<StatefulWidget> createState() => NativeAdState();\n}\n\nclass NativeAdState extends State<NativeAdWidget> {\n NativeAd _nativeAd;\n final Completer<NativeAd> nativeAdCompleter = Completer<NativeAd>();\n\n @override\n void initState() {\n super.initState();\n _nativeAd = NativeAd(\n adUnitId: NativeAd.testAdUnitId,\n request: AdRequest(),\n factoryId: \'adFactoryExample\',\n listener: AdListener(\n onAdLoaded: (Ad ad) {\n print(\'$NativeAd loaded.\');\n nativeAdCompleter.complete(ad as NativeAd);\n },\n onAdFailedToLoad: (Ad ad, LoadAdError error) {\n ad.dispose();\n print(\'$NativeAd failedToLoad: $error\');\n nativeAdCompleter.completeError(null);\n },\n onAdOpened: (Ad ad) => print(\'$NativeAd onAdOpened.\'),\n onAdClosed: (Ad ad) => print(\'$NativeAd onAdClosed.\'),\n onApplicationExit: (Ad ad) => print(\'$NativeAd onApplicationExit.\'),\n ),\n );\n Future<void>.delayed(Duration(seconds: 1), () => _nativeAd?.load());\n }\n\n @override\n void dispose() {\n super.dispose();\n _nativeAd?.dispose();\n _nativeAd = null;\n }\n\n @override\n Widget build(BuildContext context) {\n return FutureBuilder<NativeAd>(\n future: nativeAdCompleter.future,\n builder: (BuildContext context, AsyncSnapshot<NativeAd> snapshot) {\n Widget child;\n\n switch (snapshot.connectionState) {\n case ConnectionState.none:\n case ConnectionState.waiting:\n case ConnectionState.active:\n child = Container();\n break;\n case ConnectionState.done:\n if (snapshot.hasData) {\n child = AdWidget(ad: _nativeAd);\n } else {\n child = Text(\'Error loading $NativeAd\');\n }\n }\n\n return Container(\n width: 250,\n height: 350,\n child: child,\n color: Colors.blueGrey,\n );\n },\n );\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n我这样称呼原生广告
\n\n\nadWidget = NativeAdWidget(),
\n
也许我收到此错误是因为我的factoryid 为空?
\n我使用了这个插件的横幅广告,工作正常..
\n\nShr*_*gmi -1
您没有完成原生广告伙伴的所有设置部分。您还需要在 JAVA 中进行一些设置。
根据文档:
平台设置
原生广告通过平台原生的 UI 组件呈现给用户。(例如 Android 上的视图或 iOS 上的 UIView)。由于原生广告需要平台原生的 UI 组件,因此此功能需要针对 Android 和 iOS 进行额外设置。
您可以在插件文档本身中找到所有内容https://pub.dev/packages/google_mobile_ads
| 归档时间: |
|
| 查看次数: |
2678 次 |
| 最近记录: |