应用运行时 Flutter Google Map API 问题

Posted

技术标签:

【中文标题】应用运行时 Flutter Google Map API 问题【英文标题】:Flutter Google Map API Issue when App Runs 【发布时间】:2020-07-01 10:55:14 【问题描述】:

我目前正在开发一个用于跟踪患者的应用程序。所以我使用谷歌地图,我从谷歌云平台获取了 API 密钥,并限制了 android Map SDK 的密钥

然后我更改了 android manifest.xml 和 ios runners 和 plist

当我运行应用程序时,它显示以下错误

E/flutter ( 4675): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, java.lang.IllegalStateException: Trying to create an already created platform view, view id: 0
E/flutter ( 4675):  at io.flutter.plugin.platform.PlatformViewsController$1.createPlatformView(PlatformViewsController.java:85)
E/flutter ( 4675):  at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:96)
E/flutter ( 4675):  at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:60)
E/flutter ( 4675):  at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:231)
E/flutter ( 4675):  at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:93)
E/flutter ( 4675):  at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:642)
E/flutter ( 4675):  at android.os.MessageQueue.nativePollOnce(Native Method)
E/flutter ( 4675):  at android.os.MessageQueue.next(MessageQueue.java:326)
E/flutter ( 4675):  at android.os.Looper.loop(Looper.java:160)
E/flutter ( 4675):  at android.app.ActivityThread.main(ActivityThread.java:6669)
E/flutter ( 4675):  at java.lang.reflect.Method.invoke(Native Method)
E/flutter ( 4675):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/flutter ( 4675):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
E/flutter ( 4675): , null)
E/flutter ( 4675): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
E/flutter ( 4675): #1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321:33)
E/flutter ( 4675): <asynchronous suspension>
E/flutter ( 4675): #2      AndroidViewController._create (package:flutter/src/services/platform_views.dart:640:54)
E/flutter ( 4675): #3      AndroidViewController.setSize (package:flutter/src/services/platform_views.dart:557:14)
E/flutter ( 4675): #4      RenderAndroidView._sizePlatformView (package:flutter/src/rendering/platform_view.dart:174:29)
E/flutter ( 4675): #5      RenderAndroidView.performResize (package:flutter/src/rendering/platform_view.dart:155:5)
E/flutter ( 4675): #6      RenderObject.layout (package:flutter/src/rendering/object.dart:1703:9)
E/flutter ( 4675): #7      RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
E/flutter ( 4675): #8      RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
E/flutter ( 4675): #9      MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:163:11)
E/flutter ( 4675): #10     _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:477:7)
E/flutter ( 4675): #11     MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:232:7)
E/flutter ( 4675): #12     RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:391:14)
E/flutter ( 4675): #13     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
E/flutter ( 4675): #14     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
E/flutter ( 4675): #15     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
E/flutter ( 4675): #16     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
E/flutter ( 4675): #17     _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1232:11)
E/flutter ( 4675): #18     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
E/flutter ( 4675): #19     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
E/flutter ( 4675): #20     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
E/flutter ( 4675): #21     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
E/flutter ( 4675): #22     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
E/flutter ( 4675): #23     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
E/flutter ( 4675): #24     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
E/flutter ( 4675): #25     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
E/flutter ( 4675): #26     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
E/flutter ( 4675): #27     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
E/flutter ( 4675): #28     RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
E/flutter ( 4675): #29     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
E/flutter ( 4675): #30     RenderObject.layout (package:flutter/src/rende

我已经为调试这个错误做了所有的事情(尝试了 10 次以上)。如果您能帮我解决这个问题,请提前感谢。

【问题讨论】:

请检查一下SO post。您似乎遇到了同样的问题。这篇文章中的答案可能会对您有所帮助。 没错。我也参考他们。但是我做了很多事情,比如控制台命令和重建模拟器 【参考方案1】:

希望我在命令行中运行这些命令flutter cleanflutter pub cache repair 时找到了答案,它工作正常。除此之外,我的模拟器还没有安装 google paly 服务。然后当我重建并运行它时。它工作正常。

但是 google 在实现 API 的下一个版本时需要考虑这些异常

【讨论】:

以上是关于应用运行时 Flutter Google Map API 问题的主要内容,如果未能解决你的问题,请参考以下文章

使用 Flutter 在 Google Map 中的折线点中的多个标记

Flutter 应用程序“没有 Google Play 服务将无法运行”

如何打印几个标记google map api 0.5.7 Flutter

如何在 Flutter 应用程序中获取 Google API 密钥

Flutter iOS Map 样式未应用

Flutter Google Maps 显示应用程序包的空白屏幕?