diff --git a/flutter_cache_manager_firebase/CHANGELOG.md b/flutter_cache_manager_firebase/CHANGELOG.md index 2c1a7547..6628afc3 100644 --- a/flutter_cache_manager_firebase/CHANGELOG.md +++ b/flutter_cache_manager_firebase/CHANGELOG.md @@ -1,22 +1,29 @@ ## [2.0.3] - 2024-07-23 + * Updates dependencies ([#457](https://github.com/Baseflow/flutter_cache_manager/pull/457)) ## [2.0.2] - 2024-04-25 + * Updates dependencies to their latest versions. ## [2.0.1] - 2021-08-27 + * Update dependencies ## [2.0.0] - 2021-05-28 + * Update to null safety ## [1.1.0] - 2021-01-14 + * Update Firebase dependency ## [1.1.0-beta] - 2020-10-02 + * Update CacheManager dependency to 2.x.x. ## [1.0.1] - Update firebase dependency + * Added support for version 4.x.x ## [1.0.0] - Initial release diff --git a/flutter_cache_manager_firebase/lib/src/firebase_cache_manager.dart b/flutter_cache_manager_firebase/lib/src/firebase_cache_manager.dart index d474901f..08c44187 100644 --- a/flutter_cache_manager_firebase/lib/src/firebase_cache_manager.dart +++ b/flutter_cache_manager_firebase/lib/src/firebase_cache_manager.dart @@ -1,4 +1,5 @@ import 'package:flutter_cache_manager/flutter_cache_manager.dart'; +import 'package:retry/retry.dart'; import 'firebase_http_file_service.dart'; @@ -7,12 +8,18 @@ import 'firebase_http_file_service.dart'; class FirebaseCacheManager extends CacheManager { static const key = 'firebaseCache'; - static final FirebaseCacheManager _instance = FirebaseCacheManager._(); + static final FirebaseCacheManager _instance = FirebaseCacheManager._(null); + + final RetryOptions? retryOptions; factory FirebaseCacheManager() { return _instance; } - FirebaseCacheManager._() + FirebaseCacheManager.retry({this.retryOptions = const RetryOptions()}) + : super(Config(key, + fileService: FirebaseHttpFileService(retryOptions: retryOptions))); + + FirebaseCacheManager._(this.retryOptions) : super(Config(key, fileService: FirebaseHttpFileService())); } diff --git a/flutter_cache_manager_firebase/lib/src/firebase_http_file_service.dart b/flutter_cache_manager_firebase/lib/src/firebase_http_file_service.dart index c73710bc..301d0947 100644 --- a/flutter_cache_manager_firebase/lib/src/firebase_http_file_service.dart +++ b/flutter_cache_manager_firebase/lib/src/firebase_http_file_service.dart @@ -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 get(String url, {Map? 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); } } diff --git a/flutter_cache_manager_firebase/pubspec.yaml b/flutter_cache_manager_firebase/pubspec.yaml index 7924eaf8..18bd7396 100644 --- a/flutter_cache_manager_firebase/pubspec.yaml +++ b/flutter_cache_manager_firebase/pubspec.yaml @@ -13,6 +13,7 @@ dependencies: firebase_storage: '>=12.0.0 <13.0.0' path_provider: ^2.1.2 path: ^1.9.0 + retry: ^3.1.2 dev_dependencies: flutter_lints: ^4.0.0