1

我正在使用google_mobile_ads插件来显示此代码本中建议的广告。我在现有的应用程序上尝试了这个,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(),
                    height: _ad.size.height.toDouble(),
                    alignment: Alignment.topCenter,
            ),)
          ])
    );
  }

以下是我编写的bannerad初始化代码initState类似于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();

在此处输入图像描述

4

0 回答 0