Adwidget google_mobile_ads flutter 横幅在 Android 上挂起摄像头,但在 iOS 中不挂起

时间:2021-04-16 08:27:35

标签: android flutter googlemobileads flutter2.0

我使用 google_mobile_ads 插件按照建议的 in this codebook 显示广告。 我在我现有的应用程序上尝试使用 cameratflite 插件来显示横幅广告。我能够成功显示广告,但相机完全挂起(在模拟器、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,
            ),)
          ])
    );
  }

以下是我用 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();

enter image description here

0 个答案:

没有答案