receiveURL method

Future<String?> receiveURL(
  1. String storageURL, {
  2. bool useCaching = true,
  3. bool storeInCache = true,
})

Implementation

Future<String?> receiveURL(String storageURL,
    {bool useCaching = true, bool storeInCache = true}) async {
  // try getting the download link from persistency
  if (useCaching) {
    try {
      persistentKeyValueStore ??= await SharedPreferences.getInstance();
      final String? cachedURL =
          persistentKeyValueStore!.getString(storageURL);
      if (cachedURL != null) {
        return cachedURL;
      }
    } on Exception catch (error, stackTrace) {
      print(error);
      print(stackTrace);
    }
  }

  // if downloadLink is null get it from the storage
  try {
    final String downloadLink =
        await _storageInstance.ref().child(storageURL).getDownloadURL();

    // cache link
    if (useCaching || storeInCache) {
      await persistentKeyValueStore!.setString(storageURL, downloadLink);
    }

    // give url to caller
    return downloadLink;
  } on Exception {
    // print(error);
    // print(stackTrace);
  }
  return null;
}