问题描述
我使用 google_mobile_ads
插件按照建议的 in this codebook 显示广告。
我在我现有的应用程序上尝试使用 camera
和 tflite
插件来显示横幅广告。我能够成功显示广告,但相机完全挂起(在模拟器、oneplus5、samsung m31 中)。在模拟器中,我无法在虚拟环境中移动摄像头,手机摄像头可能下降到 1fps 并感觉卡住了。即使未加载实时广告且未显示任何内容,问题仍然存在。在 iOS
上构建的相同代码似乎没有任何问题。
一旦我删除了 Adwidget
,并添加了一个简单的 Text
,问题就会消失。以下是我的小部件构建代码:
Widget build(BuildContext context) {
Size screen = MediaQuery.of(context).size;
return Container(
child: Stack(
children: [
Camera(
widget.cameras,_loadedModel,setRecognitions,),Container(
width: screen.width,height: _ad.size.height.todouble(),child:Container(
// child: Text("XZCXZCZXCXZC"),// Uncommenting this and commenting Adwidget code makes the hang/lag issue go away
child: AdWidget(ad: _ad),width: _ad.size.width.todouble(),alignment: Alignment.topCenter,)
])
);
}
以下是我用 initState
(similar to the cookbook) 编写的横幅广告初始化代码
_ad = BannerAd(
adUnitId: AdManager.bannerAdUnitId,size: AdSize.banner,request: adRequest,listener: AdListener(
onAdLoaded: (_) {
setState(() {
_isAdLoaded = true;
});
},onAdFailedToLoad: (ad,error) {
// Releases an ad resource when it fails to load
ad.dispose();
print('Ad load Failed (code=${error.code} message=${error.message})');
},);
_ad.load();
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)