Skip to content

Commit

Permalink
Merge pull request #415 from percula/develop
Browse files Browse the repository at this point in the history
chore: Update dependencies for Firebase Cache Manager
  • Loading branch information
martijn00 authored Jul 31, 2024
2 parents 08e671d + 530f20c commit 479f341
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
7 changes: 7 additions & 0 deletions flutter_cache_manager_firebase/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:retry/retry.dart';

import 'firebase_http_file_service.dart';

Expand All @@ -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()));
}
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);
}
}
1 change: 1 addition & 0 deletions flutter_cache_manager_firebase/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 479f341

Please sign in to comment.