Skip to content

Commit 776fb13

Browse files
authored
Merge pull request #278 from Jjagg/nnbd
Migrate to NNBD
2 parents c869918 + c6c6fb6 commit 776fb13

46 files changed

Lines changed: 820 additions & 471 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

flutter_cache_manager/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## [3.0.0-nullsafety.3] - 2021-03-26
2+
* Add null-check on id in removeFile
3+
4+
## [3.0.0-nullsafety.2] - 2021-03-22
5+
* Fix sqflite warning
6+
7+
## [3.0.0-nullsafety.1] - 2021-03-02
8+
* Bug fix for NonStoringObjectProvider.
9+
10+
## [3.0.0-nullsafety.0] - 2021-02-25
11+
* Migration to nullsafety.
12+
113
## [2.1.2] - 2021-03-09
214
* Update dependencies
315
* Bug fix for JsonCacheInfoRepository when file is corrupted.

flutter_cache_manager/analysis_options.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ analyzer:
99
unused_local_variable: warning
1010
dead_code: warning
1111
invalid_override_of_non_virtual_member: error
12-
enable-experiment:
13-
- extension-methods
1412

1513
linter:
1614
rules:

flutter_cache_manager/example/lib/generated_plugin_registrant.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Generated file. Do not edit.
33
//
44

5+
// ignore_for_file: lines_longer_than_80_chars
6+
57
import 'package:url_launcher_web/url_launcher_web.dart';
68

79
import 'package:flutter_web_plugins/flutter_web_plugins.dart';

flutter_cache_manager/example/lib/plugin_example/file_info_widget.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class FileInfoWidget extends StatelessWidget {
3131
),
3232
Padding(
3333
padding: const EdgeInsets.all(10.0),
34+
// ignore: deprecated_member_use
3435
child: RaisedButton(
3536
child: const Text('CLEAR CACHE'),
3637
onPressed: clearCache,

flutter_cache_manager/example/pubspec.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
name: example
22
description: A new Flutter project.
3+
publish_to: none
34

45
version: 1.0.0+1
56

67
environment:
78
sdk: ">=2.10.2 <3.0.0"
89

910
dependencies:
11+
baseflow_plugin_template:
12+
git:
13+
url: git://github.com/Baseflow/baseflow_plugin_template.git
14+
ref: v1.0.0
15+
cupertino_icons: ^1.0.2
1016
flutter:
1117
sdk: flutter
12-
1318
flutter_cache_manager:
1419
path: ../
15-
cupertino_icons: ^1.0.2
1620
url_launcher: ^5.4.11
17-
baseflow_plugin_template:
18-
git:
19-
url: git://github.com/Baseflow/baseflow_plugin_template.git
20-
ref: v1.0.0
2121

2222
dev_dependencies:
2323
flutter_test:

flutter_cache_manager/example/windows/flutter/generated_plugin_registrant.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Generated file. Do not edit.
33
//
44

5+
// clang-format off
6+
57
#include "generated_plugin_registrant.h"
68

79
#include <url_launcher_windows/url_launcher_plugin.h>

flutter_cache_manager/example/windows/flutter/generated_plugin_registrant.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Generated file. Do not edit.
33
//
44

5+
// clang-format off
6+
57
#ifndef GENERATED_PLUGIN_REGISTRANT_
68
#define GENERATED_PLUGIN_REGISTRANT_
79

flutter_cache_manager/lib/src/cache_manager.dart

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,33 +35,32 @@ class CacheManager implements BaseCacheManager {
3535
/// The [fileService] can be used to customize how files are downloaded. For example
3636
/// to edit the urls, add headers or use a proxy. You can also choose to supply
3737
/// a CacheStore or WebHelper directly if you want more customization.
38-
CacheManager(Config config) {
39-
_config = config;
40-
_store = CacheStore(config);
38+
CacheManager(Config config)
39+
: _config = config,
40+
_store = CacheStore(config) {
4141
_webHelper = WebHelper(_store, config.fileService);
4242
}
4343

4444
@visibleForTesting
4545
CacheManager.custom(
4646
Config config, {
47-
CacheStore cacheStore,
48-
WebHelper webHelper,
49-
}) {
50-
_config = config;
51-
_store = cacheStore ?? CacheStore(config);
47+
CacheStore? cacheStore,
48+
WebHelper? webHelper,
49+
}) : _config = config,
50+
_store = cacheStore ?? CacheStore(config) {
5251
_webHelper = webHelper ?? WebHelper(_store, config.fileService);
5352
}
5453

55-
Config _config;
54+
final Config _config;
5655

5756
/// Store helper for cached files
58-
CacheStore _store;
57+
final CacheStore _store;
5958

6059
/// Get the underlying store helper
6160
CacheStore get store => _store;
6261

6362
/// WebHelper to download and store files
64-
WebHelper _webHelper;
63+
late final WebHelper _webHelper;
6564

6665
/// Get the underlying web helper
6766
WebHelper get webHelper => _webHelper;
@@ -74,8 +73,8 @@ class CacheManager implements BaseCacheManager {
7473
@override
7574
Future<File> getSingleFile(
7675
String url, {
77-
String key,
78-
Map<String, String> headers,
76+
String? key,
77+
Map<String, String>? headers,
7978
}) async {
8079
key ??= url;
8180
final cacheFile = await getFileFromCache(key);
@@ -95,12 +94,12 @@ class CacheManager implements BaseCacheManager {
9594
@override
9695
@Deprecated('Prefer to use the new getFileStream method')
9796
Stream<FileInfo> getFile(String url,
98-
{String key, Map<String, String> headers}) {
97+
{String? key, Map<String, String>? headers}) {
9998
return getFileStream(
10099
url,
101100
key: key,
102101
withProgress: false,
103-
).map((r) => r as FileInfo);
102+
).where((r) => r is FileInfo).cast<FileInfo>();
104103
}
105104

106105
/// Get the file from the cache and/or online, depending on availability and age.
@@ -116,18 +115,17 @@ class CacheManager implements BaseCacheManager {
116115
/// might be outdated and a new file is being downloaded in the background.
117116
@override
118117
Stream<FileResponse> getFileStream(String url,
119-
{String key, Map<String, String> headers, bool withProgress}) {
118+
{String? key, Map<String, String>? headers, bool withProgress = false}) {
120119
key ??= url;
121120
final streamController = StreamController<FileResponse>();
122-
_pushFileToStream(
123-
streamController, url, key, headers, withProgress ?? false);
121+
_pushFileToStream(streamController, url, key, headers, withProgress);
124122
return streamController.stream;
125123
}
126124

127125
Future<void> _pushFileToStream(StreamController streamController, String url,
128-
String key, Map<String, String> headers, bool withProgress) async {
126+
String? key, Map<String, String>? headers, bool withProgress) async {
129127
key ??= url;
130-
FileInfo cacheFile;
128+
FileInfo? cacheFile;
131129
try {
132130
cacheFile = await getFileFromCache(key);
133131
if (cacheFile != null) {
@@ -166,7 +164,9 @@ class CacheManager implements BaseCacheManager {
166164
///Download the file and add to cache
167165
@override
168166
Future<FileInfo> downloadFile(String url,
169-
{String key, Map<String, String> authHeaders, bool force = false}) async {
167+
{String? key,
168+
Map<String, String>? authHeaders,
169+
bool force = false}) async {
170170
key ??= url;
171171
var fileResponse = await _webHelper
172172
.downloadFile(
@@ -182,13 +182,13 @@ class CacheManager implements BaseCacheManager {
182182
/// Get the file from the cache.
183183
/// Specify [ignoreMemCache] to force a re-read from the database
184184
@override
185-
Future<FileInfo> getFileFromCache(String key,
185+
Future<FileInfo?> getFileFromCache(String key,
186186
{bool ignoreMemCache = false}) =>
187187
_store.getFile(key, ignoreMemCache: ignoreMemCache);
188188

189189
///Returns the file from memory if it has already been fetched
190190
@override
191-
Future<FileInfo> getFileFromMemory(String key) =>
191+
Future<FileInfo?> getFileFromMemory(String key) =>
192192
_store.getFileFromMemory(key);
193193

194194
/// Put a file in the cache. It is recommended to specify the [eTag] and the
@@ -201,15 +201,19 @@ class CacheManager implements BaseCacheManager {
201201
Future<File> putFile(
202202
String url,
203203
Uint8List fileBytes, {
204-
String key,
205-
String eTag,
204+
String? key,
205+
String? eTag,
206206
Duration maxAge = const Duration(days: 30),
207207
String fileExtension = 'file',
208208
}) async {
209209
key ??= url;
210210
var cacheObject = await _store.retrieveCacheData(key);
211-
cacheObject ??= CacheObject(url,
212-
key: key, relativePath: '${Uuid().v1()}.$fileExtension');
211+
cacheObject ??= CacheObject(
212+
url,
213+
key: key,
214+
relativePath: '${const Uuid().v1()}.$fileExtension',
215+
validTill: DateTime.now().add(maxAge),
216+
);
213217

214218
cacheObject = cacheObject.copyWith(
215219
validTill: DateTime.now().add(maxAge),
@@ -233,17 +237,18 @@ class CacheManager implements BaseCacheManager {
233237
Future<File> putFileStream(
234238
String url,
235239
Stream<List<int>> source, {
236-
String key,
237-
String eTag,
240+
String? key,
241+
String? eTag,
238242
Duration maxAge = const Duration(days: 30),
239243
String fileExtension = 'file',
240244
}) async {
241245
key ??= url;
242246
var cacheObject = await _store.retrieveCacheData(key);
243247
cacheObject ??= CacheObject(url,
244248
key: key,
245-
relativePath: '${Uuid().v1()}'
246-
'.$fileExtension');
249+
relativePath: '${const Uuid().v1()}'
250+
'.$fileExtension',
251+
validTill: DateTime.now().add(maxAge));
247252

248253
cacheObject = cacheObject.copyWith(
249254
validTill: DateTime.now().add(maxAge),
@@ -267,8 +272,8 @@ class CacheManager implements BaseCacheManager {
267272
@override
268273
Future<void> removeFile(String key) async {
269274
final cacheObject = await _store.retrieveCacheData(key);
270-
if (cacheObject != null) {
271-
await _store.removeCachedFile(cacheObject);
275+
if (cacheObject?.id != null) {
276+
await _store.removeCachedFile(cacheObject!);
272277
}
273278
}
274279

flutter_cache_manager/lib/src/cache_managers/base_cache_manager.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ abstract class BaseCacheManager {
3939
/// returned from the cache there will be no progress given, although the file
4040
/// might be outdated and a new file is being downloaded in the background.
4141
Stream<FileResponse> getFileStream(String url,
42-
{String key, Map<String, String> headers, bool withProgress});
42+
{String? key, Map<String, String>? headers, bool withProgress});
4343

4444
///Download the file and add to cache
4545
Future<FileInfo> downloadFile(String url,
46-
{String key, Map<String, String> authHeaders, bool force = false});
46+
{String? key, Map<String, String>? authHeaders, bool force = false});
4747

4848
/// Get the file from the cache.
4949
/// Specify [ignoreMemCache] to force a re-read from the database
50-
Future<FileInfo> getFileFromCache(String key, {bool ignoreMemCache = false});
50+
Future<FileInfo?> getFileFromCache(String key, {bool ignoreMemCache = false});
5151

5252
///Returns the file from memory if it has already been fetched
53-
Future<FileInfo> getFileFromMemory(String key);
53+
Future<FileInfo?> getFileFromMemory(String key);
5454

5555
/// Put a file in the cache. It is recommended to specify the [eTag] and the
5656
/// [maxAge]. When [maxAge] is passed and the eTag is not set the file will
@@ -61,8 +61,8 @@ abstract class BaseCacheManager {
6161
Future<File> putFile(
6262
String url,
6363
Uint8List fileBytes, {
64-
String key,
65-
String eTag,
64+
String? key,
65+
String? eTag,
6666
Duration maxAge = const Duration(days: 30),
6767
String fileExtension = 'file',
6868
});
@@ -77,8 +77,8 @@ abstract class BaseCacheManager {
7777
Future<File> putFileStream(
7878
String url,
7979
Stream<List<int>> source, {
80-
String key,
81-
String eTag,
80+
String? key,
81+
String? eTag,
8282
Duration maxAge = const Duration(days: 30),
8383
String fileExtension = 'file',
8484
});

flutter_cache_manager/lib/src/cache_managers/default_cache_manager.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ import '../config/config.dart';
99
class DefaultCacheManager extends CacheManager with ImageCacheManager {
1010
static const key = 'libCachedImageData';
1111

12-
static DefaultCacheManager _instance;
12+
static final DefaultCacheManager _instance = DefaultCacheManager._();
1313
factory DefaultCacheManager() {
14-
_instance ??= DefaultCacheManager._();
1514
return _instance;
1615
}
1716

0 commit comments

Comments
 (0)