Correct way of storing API Keys in flutter following best practises

前端 未结 4 1199
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-23 14:36

Which is the correct way(best practice) of adding secret API keys in flutter in case I want to push the code on github. I\'ve made a simple app that consumes an API b

4条回答
  •  太阳男子
    2020-12-23 15:06

    Edit: Look at J. Saw's comment below

    Use Firebase Remote Config. Inside the Firebase console, inside the menu, scroll down to Grow and then Remote Config. Here you can add a parameter with a value. When you're done don't forget to publish the changes. It's kind of subtle.

    Now install firebase_remote_config for Flutter.

    After importing everything, you can retrieve your value using this code:

    RemoteConfig remoteConfig = await RemoteConfig.instance;
    await remoteConfig.fetch(expiration: Duration(hours: 1));
    await remoteConfig.activateFetched();
    
    remoteConfig.getValue('key').asString();
    

    This way, the API key or token is never part of your application.

    Note: there is currently an issue where you get a warning stating the application's name is not set, but this won't affect functionality.

提交回复
热议问题