Reputation: 1658
I have a google map on the very first page of my application after the splash screen. When I run the app for the first time and a very new build, it crashes with this error on IOS: PlatformException(create_failed, can't create a view on a headless engine, null).
This is my google Map code and the crash happens only in IOS for the first time when the app is installed.
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,
)
I am following up on this issue on GitHub : https://github.com/flutter/flutter/issues/36310 but it is not having a proper solution. Can anyone please help me with this?
Upvotes: 9
Views: 2760
Reputation: 525
Have you registered your API key properly and in the right spot? This needs to be registered within the appDelegate class before the flutter engine kicks in. (Please note that this is a swift file)
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)
}
}
Upvotes: 1