Flutter: Add Google Maps API key dynamically


Instead of hard coding, Google maps API key in AndroidManifest.xml and AppDelegate.swift. We can change the Google Maps key dynamically anytime.

We can store the Google Maps key on the server and can get using the rest API. Map key can change the key at runtime after getting from the server.

How to change the google maps API key dynamically?

We have to add a key at run time in native code AndroidManifest.xml and AppDelegate.swift. Flutter provides a way to communicate with native code through the Flutter platform channel.

Flutter Dart Code Implementation :

Let’s check implementation at Fluter’s Dart code end.

Native Android Code Implementation:

Let’s check implementation at Native Android end.

We have to add meta data in AndroidManifest.xml.

Receive Google Maps API key from Flutter Channel.


Native IOS Code Implementation:

Let’s check implementation at Native IOS end.


Google Maps key dynamically

I hope this blog will help to set Google Map API key dynamically.

Happy Learning 🙂

Reference Links:



. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


  • fbo
    – The Android part is outdated, please update this (fix is too long to post in comments).
    – Please add the file / location of where to add the native code for Android and iOS (useful for people who do not know the Android / iOS structure):
    Android: ‘MainActivity.kt’ located in ‘/android/app/src/main/kotlin/’
    iOS: ‘AppDelegate.swift’ lcoated in ‘/ios/Runner/’
    – There is a big fault in the iOS code. The FlutterMethodChannel’s name is set to “plugins.flutter.io/firebase_messaging_background”. This should be “com.map_api_key.flutter”.

    Not the best tutorial, not even tested (see last point). But unfortunately the only one that explains both platforms.

  • css.php

    We've bought a Shopware Extension which is a hybrid App, which we can now offer in the Google Play Store and the IOS App Store. I'am still impressed how fast and how sharp the support team leads us through every process of the App-Store clarification. Very fast and useful response.

    Markus Walter

    Markus Walter

    Founder, Das Apartment Living

    Talk to Sales


    Live Chat
    Start a Project

      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home