-
-
Notifications
You must be signed in to change notification settings - Fork 441
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #415 from percula/develop
chore: Update dependencies for Firebase Cache Manager
- Loading branch information
Showing
4 changed files
with
33 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 16 additions & 1 deletion
17
flutter_cache_manager_firebase/lib/src/firebase_http_file_service.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,31 @@ | ||
import 'package:firebase_storage/firebase_storage.dart'; | ||
import 'package:flutter_cache_manager/flutter_cache_manager.dart'; | ||
import 'package:retry/retry.dart'; | ||
|
||
/// [FirebaseHttpFileService] is another common file service which parses a | ||
/// firebase reference into, to standard url which can be passed to the | ||
/// standard [HttpFileService]. | ||
class FirebaseHttpFileService extends HttpFileService { | ||
final RetryOptions? retryOptions; | ||
|
||
FirebaseHttpFileService({ | ||
this.retryOptions, | ||
}); | ||
|
||
@override | ||
Future<FileServiceResponse> get(String url, | ||
{Map<String, String>? headers}) async { | ||
var ref = FirebaseStorage.instance.ref().child(url); | ||
var downloadUrl = await ref.getDownloadURL(); | ||
|
||
String downloadUrl; | ||
if (retryOptions != null) { | ||
downloadUrl = await retryOptions!.retry( | ||
() async => await ref.getDownloadURL(), | ||
retryIf: (e) => e is FirebaseException, | ||
); | ||
} else { | ||
downloadUrl = await ref.getDownloadURL(); | ||
} | ||
return super.get(downloadUrl); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters