我正在使用一个名为 Model Viewer ModelViewer
的颤振库这是一个非常好的插件,它在我的开发版应用程序上的作用就像魅力一样。我是这样使用它的:
ModelViewer(
backgroundColor: Colors.black,
src: 'assets/skull.glb',
alt: "A 3D model of a skull",
cameraControls: true,
),
.glb 模型位于资产文件夹中。 我的flutter是最新的稳定版本,也是这个插件的版本。
奇怪的是,当我构建应用程序包并在 google play 上发布应用程序时,当我使用模型查看器导航到页面时,小部件永远不会加载。
我只能看到白屏。
开发版和发行版均在运行 Android 10 的物理设备上进行测试。
我不知道如何调试这个,但很乐意提供任何建议。无法从原始存储库中找到任何解决方案。
更新
这是来自 logcat 的错误:
2021-04-07 21:42:49.592 8121-8147/? E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: NoSuchMethodError: The getter 'address' was called on null.
Receiver: null
Tried calling: address
#0 _ModelViewerState.build.<anonymous closure> (package:model_viewer/src/model_viewer.dart:127)
#1 _ModelViewerState.build.<anonymous closure> (package:model_viewer/src/model_viewer.dart:125)
#2 _WebViewState._onWebViewPlatformCreated (package:webview_flutter/webview_flutter.dart:375)
#3 CupertinoWebView.build.<anonymous closure> (package:webview_flutter/src/webview_cupertino.dart:35)
#4 AndroidViewController.create (package:flutter/src/services/platform_views.dart:746)
<asynchronous suspension>
#5 RenderAndroidView._sizePlatformView (package:flutter/src/rendering/platform_view.dart:195)
<asynchronous suspension>
谢谢。
答案 0 :(得分:1)
本地服务器由库 (in model_viewer.dart
) 使用 _proxy = await HttpServer.bind(InternetAddress.loopbackIPv4, 0);
创建。 WebView 连接到此服务器并显示模型。我们使用 HttpServer.bind
创建的网络服务器提供了一些文件:一个 html 文件、一个 javascript 文件、模型和 favicon.ico。
代码不会根据调试/发布而改变,但实际上是因为调试模式构建自动具有允许访问互联网的权限,但Android版本没有。所以 WebView 只有在调试时才能成功连接到服务器。我只从 here 中发现了有关调试构建的自动 Internet 权限。因此,构建发布应用程序(不上传到 Play 商店)也应该解决这个问题。
大多数人不会发现这是一个问题,因为他们的应用在添加 3D 模型时需要互联网许可,或者他们使用的是远程 3D 模型。我已就此问题回复 GitHub issue,并建议将权限添加到 README。您可能有兴趣为 repo 创建一个关于它的 PR。 :)
答案 1 :(得分:0)
找到了这个问题的解决方案。
当您使用模型查看器时,您需要添加:
<uses-permission android:name="android.permission.INTERNET"/>
到您的 AndroidManifest.xml
文件。
这样,Widget 将能够模拟模型。
通常它是在本地服务器上执行的,也就是 localhost,但是当它发布时,它会改变。
希望有人会觉得它有用。