Check Mobile App
Read now
Start a Project

Flutter: Add Google Maps API key dynamically

Save

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:

https://mobikul.com/flutter-platform-channel/

https://flutter.dev/docs/development/platform-integration/platform-channels

. . .

Leave a Comment

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


1 comments

  • 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

    When I think in getting solutions for my Ecommerce Platform, I think of Webkul. They have been such a blessing in our business. We have spent thousands of dollars in support and modules from them. We love their support team. They work very closely with us, and they always go the extra mile when we need help.

    Michael Urresta

    Michael Urresta

    Talk to Sales

    Global

    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