-
-
Notifications
You must be signed in to change notification settings - Fork 458
Migrate to NNBD #278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate to NNBD #278
Conversation
_memCache.remove(key); | ||
} else { | ||
_memCache[key] = cacheObject; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Behavior change here. Seemed to make sense to me to remove null
values and make the cached items non-nullable.
@@ -22,5 +22,5 @@ class FileInfo extends FileResponse { | |||
|
|||
/// Validity date of the file. After this date the validity is not guaranteed | |||
/// and the CacheManager will try to update the file. | |||
final DateTime validTill; | |||
final DateTime? validTill; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if this actually should be null. Had to use a lot of bangs because I made it nullable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to make it required.
when(provider.open()).thenAnswer((_) => Future.value(true)); | ||
when(provider.update(any, setTouchedToNow: anyNamed('setTouchedToNow'))) | ||
.thenAnswer((realInvocation) => Future.value(0)); | ||
when(provider.updateOrInsert(any)).thenAnswer((realInvocation) async => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can let Mockito return null
for unstubbed methods, but I did not enable that because it can cause runtime casting errors with NNBD. Downside is all methods need to be stubbed explicitly.
}), | ||
returnValue: Stream<_i10.FileResponse>.empty()) | ||
as _i7.Stream<_i10.FileResponse>); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might prefer not having this generated file checked in, LMK.
flutter_cache_manager/lib/src/cache_managers/default_cache_manager.dart
Outdated
Show resolved
Hide resolved
Dart beta has been already release, please publish it. https://medium.com/dartlang/preparing-the-dart-and-flutter-ecosystem-for-null-safety-e550ce72c010 |
Thanks for reviewing @hoc081098, I made some changes. |
@Jjagg I wanted to start with this today, but found your PR.
This should just be I don't mind any breaking changes, as long as it is documented. That's why this will be a new major version. |
IMO a caching library should not throw an exception when an item is retrieved that is not in the cache. But I don't have too strong of an opinion on it and I don't use this library directly, so it doesn't matter much to me. I've given you access to my fork. Feel free to commit directly to this branch or branch off and set up your own pull request/commit directly to the main branch. Either would be a little faster than you commenting and me making the changes :) |
I'm also not 100% sure about the best way, I think both null and an exception are fine if documented well. |
From Effective Dart:
And from the Language Tour:
I agree that for a caching library, a cache miss is not an error but something to be expected. |
Hi- the force unwrap here is causing a runtime error for me:
|
@acoutts I'll update dependencies to the stable version for packages where it's already available and fix that issue. |
I'm not overriding it no- i'm on |
I was able to silence the error with this override: dependency_overrides:
path_provider: 2.0.0-nullsafety.1 |
# Conflicts: # flutter_cache_manager/lib/src/storage/cache_info_repositories/json_cache_info_repository.dart
In the latest stable of path_provider they changed the return type from Future<Directory?> to Future I upgraded the dependencies that have a stable version now. |
// test('Non-existing cacheFile should call to web', () async { | ||
// var fileName = 'test.jpg'; | ||
// var fileUrl = 'baseflow.com/test'; | ||
// var fileKey = 'test1234'; | ||
// var validTill = DateTime.now().subtract(const Duration(days: 1)); | ||
// | ||
// var config = createTestConfig(); | ||
// config.returnsCacheObject(fileUrl, fileName, validTill, key: fileKey); | ||
// | ||
// var cacheManager = TestCacheManager(config); | ||
// | ||
// var result = await cacheManager.getSingleFile(fileUrl, key: fileKey); | ||
// expect(result, isNotNull); | ||
// config.verifyDownloadCall(); | ||
// }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jjagg I couldn't get this test working, do you have any idea what's going wrong here? It looks like webhelper.downloadFile is not really called, but that is not mocked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the error message?
From your comment I think it's because of the changes to mockito with NNBD.
Mocks are generated with build_runner and by default all methods throw. Any method that is called should be mocked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! Would love to get this landed. This is on our list of critical/important community packages!
Let me know if you need any help!
@@ -1,3 +1,7 @@ | |||
## [3.0.0-nullsafety.0] - 2021-02-25 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's drop the -nullsafety.0
bits. We can release stable now!
See https://medium.com/dartlang/preparing-the-dart-and-flutter-ecosystem-for-null-safety-e550ce72c010
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but besides null safety being stable we also make sure that this package is stable.
All tests are stil broken and @ryanheise also found a bug. So we can change 3.0.0-beta.0
, but that doesn't really help much.
flutter_cache_manager/pubspec.yaml
Outdated
@@ -1,26 +1,28 @@ | |||
name: flutter_cache_manager | |||
description: Generic cache manager for flutter. Saves web files on the storages of the device and saves the cache info using sqflite. | |||
version: 2.1.1 | |||
version: 3.0.0-nullsafety.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drop the -nullsafety bit here. Should be ready for stable!
flutter_cache_manager/pubspec.yaml
Outdated
image: ^2.1.18 | ||
|
||
http: ^0.13.0 | ||
image: ^3.0.0-nullsafety.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drop -nullsafety
this is published stable now!
flutter_cache_manager/pubspec.yaml
Outdated
path: ^1.8.0 | ||
path_provider: ^2.0.0 | ||
pedantic: ^1.10.0 | ||
rxdart: ^0.26.0-nullsafety.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drop -nullsafety
this is published stable now!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool!
Who has the power to merge and publish? |
That would be @renefloor :) |
@kevmoo it is already published as preview version: https://pub.dev/packages/flutter_cache_manager/versions/3.0.0-nullsafety.0 I try to migrate CachedNetworkImage this week and if I don't get any issues I'll merge and publish as stable. |
In @override
Future<CacheObject> get(String url) {
return Future.value(null);
} But The analyser didn't detect any problem statically (which is unfortunate since that should be the goal of null safety) but the documentation for
|
I'm only getting a warning, so they might have changed the analyzer behavior. Nevertheless, doesn't hurt to upgrade sqflite. |
# Conflicts: # flutter_cache_manager/CHANGELOG.md # flutter_cache_manager/example/pubspec.yaml # flutter_cache_manager/pubspec.yaml
Codecov Report
@@ Coverage Diff @@
## develop #278 +/- ##
===========================================
- Coverage 76.11% 74.73% -1.38%
===========================================
Files 21 21
Lines 674 669 -5
===========================================
- Hits 513 500 -13
- Misses 161 169 +8
Continue to review full report at Codecov.
|
This migrates the library to NNBD.
For now this only migrates the flutter_cache_manager package and its tests.
There's 2 test failures I have yet to resolve, so I'm submitting as a draft for now.
Heads up that
build_runner
needs to be run before running tests because of changes to Mockito to support NNBD.Fixes #253.
🤔 Checklist before submitting