Start a Project

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.

Check out more about our Flutter app development.

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.

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

Exit mobile version