如何在 Flutter 应用程序中获取 Google API 键

How to get Google API key in Flutter Application

我已经使用 https://pub.dev/packages/google_maps_flutter for maps and I want to add directions as per https://medium.com/@shubham.narkhede8/flutter-google-map-with-direction-6a26ad875083 构建了一个 Flutter 应用程序,但我需要获取 Google API 密钥,该密钥在构建时以不同的方式注入到应用程序中,具体取决于无论是 Android 还是 IoS.

我在谷歌上搜索了大约一个小时,但找不到 Flutter 或本机方式来访问应用程序中的 API 键。有办法吗?

如果我正确理解您正在尝试从 Flutter 中的原生 iOS 和 Android 项目访问 Google 地图 API 键,这应该工作:

使用此:https://pub.dev/packages/flutter_native_config 阅读 Android 清单和 iOS Info.plist。

在 Android 上,根据 Google 地图文档,密钥已经存在。

然后您需要将 iOS 中的 API 键移动到 info.plist 中,然后读入而不是硬编码:https://www.hackingwithswift.com/example-code/system/how-to-read-your-apps-version-from-your-infoplist-file