title: Correct way of storing API Keys in flutter following best practises
body: <p>Which is the correct way(<i>best practice</i>) 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 but I used the key in a crud way just to test whether the app is working. Usually from my experience developing applications in the back-end, Keys are stored somewhere and in different file then one would simply import it to the required file that needs the <code>API_KEY</code> and exclude the file in <code>.gitignore</code> file. </p>
  
  <p>So far I have also implemented this approach:</p>
  
  <h3>Folder tree</h3>
  
  <pre><code>-lib
    -auth
      -keys.dart
      -secrets.json 
  </code></pre>
  
  <h1>secrets.json</h1>
  
  <p><p>This is where I will add the <code>KEY</code> and specify this file in <code>.gitignore</code> to be excluded from being added in github when I push my code.</p>
  
  <pre><code>//Add API KEY HERE
  {
    "api_key": "ee4444444a095fc613c5189b2"
  }
  </code></pre>
  
  <h1>keys.dart</h1>
  
  <pre><code>import 'dart:async' show Future;
  import 'dart:convert' show json;
  import 'package:flutter/services.dart' show rootBundle;
  
  
  class Secret {
    final String apikey;
  
    Secret({this.apikey=""});
  
    factory Secret.fromJson(Map&lt;String, dynamic&gt;jsonMap){
      return new Secret(apikey:jsonMap["api_key"]);
    }
  }
  
  
  class SecretLoader {
    final String secretPath;
  
    SecretLoader({this.secretPath});
    Future&lt;Secret&gt; load() {
      return rootBundle.loadStructuredData&lt;Secret&gt;(this.secretPath,
              (jsonStr) async {
            final secret = Secret.fromJson(json.decode(jsonStr));
            return secret;
  
          });
    }
  }
  </code></pre>
  
  <p>I feel like this approach is too much. I would like to get suggestions of a better approach. </p>