Flutter谷歌地图在IOS中首次打开时崩溃



在启动屏幕后,我的应用程序的第一页上就有一个谷歌地图。当我第一次运行该应用程序并进行全新构建时,它在IOS上崩溃并出现此错误:PlatformException(create_failed,无法在无头引擎上创建视图,null(

这是我的谷歌地图代码,当应用程序安装时,崩溃只在IOS中第一次发生。

GoogleMap(
myLocationEnabled: false,
myLocationButtonEnabled: false,
zoomGesturesEnabled: true,
scrollGesturesEnabled: true,
rotateGesturesEnabled: false,
tiltGesturesEnabled: false,
onMapCreated: _onMapCreated,
initialCameraPosition: CameraPosition(
target: _location,
zoom: 12,
/* tilt: 50.0,
bearing: 45.0,*/
),
mapType: _currentMapType,
markers: Set<Marker>.of(markers.values),
onCameraMove: _onCameraMove,
onCameraIdle: _onCameraIdle,
)

我正在GitHub上跟进这个问题:https://github.com/flutter/flutter/issues/36310但它没有一个合适的解决方案。有人能帮我吗?

您是否已在正确的位置正确注册API密钥?在颤振引擎启动之前,这需要在appDelegate类中注册。(请注意,这是一个swift文件(

import UIKit
import GoogleMaps
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GMSServices.provideAPIKey("super_secret_api_key")
GeneratedPluginRegistrant.register(with: self); 
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}

最新更新