getApiKey static method

Future<String> getApiKey()

Fetches the API key from SharedPreferences. If not present, returns the default API key

Implementation

static Future<String> getApiKey() async {
  // Default API key set by default. This key is used if the user has not set a custom API key
  String apiKey = defaultNasaApiKey;

  // Getting an instance of SharedPreferences
  SharedPreferences prefs = await SharedPreferences.getInstance();

  // Checking if the API key is present in SharedPreferences and setting it as the API key if present
  if (prefs.containsKey('nasa_api_key')) {
    apiKey = prefs.getString('nasa_api_key')!;
  }

  return apiKey;
}