loadManifestData static method

Future<Map<String, dynamic>> loadManifestData()

Loads the mission manifest data from cache or fetches it from NASA's API if not present in cache

Implementation

static Future<Map<String, dynamic>> loadManifestData() async {
  // Getting an instance of SharedPreferences
  SharedPreferences prefs = await SharedPreferences.getInstance();

  // Retrieving the cached data
  String? data = prefs.getString('manifest');

  // Decoding the cached JSON data if present in cache
  if (data != null) {
    return json.decode(data);
  } else {
    // Fetching the mission manifest from API if not present in cache and storing it in cache

    // Fetching the mission manifest from API
    Map<String, dynamic> manifest = await getMissionManifest();

    // Storing the fetched data in cache
    NasaApi.storeManifestInCache(manifest);
    return manifest;
  }
}