所以我在列表中插入了 admob 广告。我在列表视图中添加了无限滚动的功能。因此,当用户滚动到列表末尾时,新项目将添加到列表中。对于这个项目,我还在其中添加了 admob 广告。
因此,当用户滚动到末尾时,新项目和广告将添加到列表中。此时会捕获以下异常。那么如何解决这个异常呢。
======== Exception caught by widgets library =======================================================
The following assertion was thrown building AdWidget-[#53ef3](dirty, state: _AdWidgetState#850ac):
This AdWidget is already in the Widget tree
If you placed this AdWidget in a list, make sure you create a new instance in the builder function with a unique ad object.
Make sure you are not using the same ad object in more than one AdWidget.
The relevant error-causing widget was:
AdWidget-[#53ef3] file:///D:/flutter%20project/memer/lib/pages/TimeLinePage.dart:198:42
When the exception was …Run Code Online (Sandbox Code Playgroud) 因此,我使用 cached_network_image: ^2.0.0 作为我的应用程序的缓存网络图像提供程序。因此,当我在模拟器上运行该应用程序并通过 USB 调试连接 Android 手机时,缓存网络图像提供程序工作完全正常。所有图像均已正确加载。
但是在构建 apk 版本(发布模式)之后,然后当我在 Android 手机上安装该应用程序时,缓存的网络图像提供程序不会加载图像。仅白色背景可见。
我还完成了 Flutter clean 并升级了 cached_network_image :^3.0.0 然后问题是一样的。
此外,当我使用 NetworkImage 作为图像时,图像可以正确加载。但我想缓存图像以提高应用程序的速度。
那么是否有人知道为什么缓存的网络图像提供程序在 USB 调试中工作得完全正常,而在安装 build app-release.apk 后却无法工作。
我的代码:-
leading: CircleAvatar(backgroundImage: CachedNetworkImageProvider(user.url)),//NetworkImage(user.url)
Run Code Online (Sandbox Code Playgroud)
提前致谢:)
android firebase flutter flutter-dependencies flutter-layout