Search code examples
iosfluttergoogle-mapsflutter-module

How to add Google Maps to a flutter module that is used inside a native iOS app


I have a native iOS app which is integrating a flutter module for a few features. Now for a new feature, I need to integrate Google maps inside the flutter module.

The documentation says we need to add Google maps initialization code inside ios/Runner/AppDelegate.m, but in my case the whole .iOS folder is regenerated in each new build, and adding things there will only make it work if I run the flutter module independently. But when I integrate the flutter module with the iOS native app, I get a crash: Google Maps SDK for iOS must be initialized via [GMSServices provideAPIKey:...] prior to use even if I have this line in the native iOS AppDelegate.

What am I missing?


Solution

  • Figured out how to solve this by initializing Google Maps library that is used in Flutter module in addition to the one used in the main app:

    So in my code I had to add a Google Maps initializer method inside the Flutter module and I called it from appDelegate in the main app after the original Google Maps initializer.