From 2149d742c54c76dc5e7496b30d83483ab6c9a03b Mon Sep 17 00:00:00 2001 From: Ted Date: Tue, 20 Apr 2021 15:20:38 +1200 Subject: [PATCH 1/9] Update method to make it compatible with dio 4 --- lib/src/manager_dio.dart | 40 +++++++++++++++++++++++----------------- pubspec.yaml | 4 ++-- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/lib/src/manager_dio.dart b/lib/src/manager_dio.dart index 33e8af7..067e0f6 100644 --- a/lib/src/manager_dio.dart +++ b/lib/src/manager_dio.dart @@ -38,38 +38,43 @@ class DioCacheManager { return _interceptor; } - _onRequest(RequestOptions options) async { + _onRequest(RequestOptions options, RequestInterceptorHandler handler) async { if ((options.extra[DIO_CACHE_KEY_TRY_CACHE] ?? false) != true) { - return options; + return handler.next(options); } if (true == options.extra[DIO_CACHE_KEY_FORCE_REFRESH]) { - return options; + return handler.next(options); } var responseDataFromCache = await _pullFromCacheBeforeMaxAge(options); if (null != responseDataFromCache) { - return _buildResponse( - responseDataFromCache, responseDataFromCache?.statusCode, options); + return handler.resolve( + _buildResponse( + responseDataFromCache, responseDataFromCache?.statusCode, options), + true, + ); } - return options; + return handler.next(options); } - _onResponse(Response response) async { - if ((response.request.extra[DIO_CACHE_KEY_TRY_CACHE] ?? false) == true && + _onResponse(Response response, ResponseInterceptorHandler handler) async { + if ((response.requestOptions.extra[DIO_CACHE_KEY_TRY_CACHE] ?? false) == + true && response.statusCode >= 200 && response.statusCode < 300) { await _pushToCache(response); } - return response; + return handler.next(response); } - _onError(DioError e) async { - if ((e.request.extra[DIO_CACHE_KEY_TRY_CACHE] ?? false) == true) { - var responseDataFromCache = await _pullFromCacheBeforeMaxStale(e.request); + _onError(DioError e, ErrorInterceptorHandler handler) async { + if ((e.requestOptions.extra[DIO_CACHE_KEY_TRY_CACHE] ?? false) == true) { + var responseDataFromCache = + await _pullFromCacheBeforeMaxStale(e.requestOptions); if (null != responseDataFromCache) - return _buildResponse(responseDataFromCache, - responseDataFromCache?.statusCode, e.request); + return handler.resolve(_buildResponse(responseDataFromCache, + responseDataFromCache?.statusCode, e.requestOptions)); } - return e; + return handler.next(e); } Response _buildResponse( @@ -90,10 +95,11 @@ class DioCacheManager { if (options.responseType != ResponseType.bytes) { data = jsonDecode(utf8.decode(data)); } + ; return Response( data: data, headers: headers, - extra: options.extra..remove(DIO_CACHE_KEY_TRY_CACHE), + requestOptions: options.extra.remove(DIO_CACHE_KEY_TRY_CACHE), statusCode: statusCode ?? 200); } @@ -110,7 +116,7 @@ class DioCacheManager { } Future _pushToCache(Response response) { - RequestOptions options = response.request; + RequestOptions options = response.requestOptions; Duration maxAge = options.extra[DIO_CACHE_KEY_MAX_AGE]; Duration maxStale = options.extra[DIO_CACHE_KEY_MAX_STALE]; if (null == maxAge) { diff --git a/pubspec.yaml b/pubspec.yaml index ce92ccf..855a0e1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -6,7 +6,7 @@ authors: homepage: https://github.com/hurshi/dio-http-cache environment: - sdk: ">=2.1.0 <3.0.0" + sdk: '>=2.1.0 <3.0.0' dependencies: flutter: @@ -14,7 +14,7 @@ dependencies: quiver: ^2.0.3 json_serializable: ^3.0.0 json_annotation: ^3.0.0 - dio: ^3.0.1 + dio: ^4.0.0 sqflite: ^1.1.6+3 path: ^1.6.2 crypto: ^2.1.1+1 From 37b7f347429a1a38a39dced9efc625f238ca6851 Mon Sep 17 00:00:00 2001 From: Ted Date: Tue, 20 Apr 2021 15:39:31 +1200 Subject: [PATCH 2/9] Bump crypto package --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 855a0e1..80cb454 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -17,7 +17,7 @@ dependencies: dio: ^4.0.0 sqflite: ^1.1.6+3 path: ^1.6.2 - crypto: ^2.1.1+1 + crypto: ^3.0.1 dev_dependencies: flutter_test: From abf309c780ecd02231f5dcb3ed055f2bfd1766ca Mon Sep 17 00:00:00 2001 From: Ted Date: Tue, 20 Apr 2021 16:18:20 +1200 Subject: [PATCH 3/9] Bump josn serializable and annotation package --- pubspec.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 80cb454..72506f8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,8 +12,8 @@ dependencies: flutter: sdk: flutter quiver: ^2.0.3 - json_serializable: ^3.0.0 - json_annotation: ^3.0.0 + json_serializable: ^4.1.0 + json_annotation: ^4.0.1 dio: ^4.0.0 sqflite: ^1.1.6+3 path: ^1.6.2 From e88ee23c7bd6e2aa366f7e0e9aa4af3331b0490a Mon Sep 17 00:00:00 2001 From: Ted Date: Tue, 20 Apr 2021 16:27:22 +1200 Subject: [PATCH 4/9] bump up quiver package version --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 72506f8..6130086 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ environment: dependencies: flutter: sdk: flutter - quiver: ^2.0.3 + quiver: ^3.0.1 json_serializable: ^4.1.0 json_annotation: ^4.0.1 dio: ^4.0.0 From 69dce134ffed66b4ec5e3169bd997744aad620af Mon Sep 17 00:00:00 2001 From: Ted Date: Wed, 21 Apr 2021 09:14:31 +1200 Subject: [PATCH 5/9] Fix remove wrong item issue --- lib/src/manager_dio.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/manager_dio.dart b/lib/src/manager_dio.dart index 067e0f6..d7854a9 100644 --- a/lib/src/manager_dio.dart +++ b/lib/src/manager_dio.dart @@ -99,7 +99,8 @@ class DioCacheManager { return Response( data: data, headers: headers, - requestOptions: options.extra.remove(DIO_CACHE_KEY_TRY_CACHE), + requestOptions: options.copyWith( + extra: options.extra..remove(DIO_CACHE_KEY_TRY_CACHE)), statusCode: statusCode ?? 200); } From c6616d7e1b0619e3a9ff4e0f500bac6e363fe7c0 Mon Sep 17 00:00:00 2001 From: Ted Date: Thu, 22 Apr 2021 10:12:15 +1200 Subject: [PATCH 6/9] Update variable name --- lib/src/core/manager.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/core/manager.dart b/lib/src/core/manager.dart index bd1d4e1..6ead50a 100644 --- a/lib/src/core/manager.dart +++ b/lib/src/core/manager.dart @@ -12,7 +12,7 @@ class CacheManager { CacheConfig _config; ICacheStore _diskCacheStore; ICacheStore _memoryCacheStore; - MD5 _md5; + Hash _md5; Utf8Encoder _utf8encoder; CacheManager(this._config) { From 4a0ec70178aa63b92515666778f0a30da512ec28 Mon Sep 17 00:00:00 2001 From: Ted Date: Tue, 27 Apr 2021 15:19:49 +1200 Subject: [PATCH 7/9] Max max-age parameter options --- lib/src/builder_dio.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/builder_dio.dart b/lib/src/builder_dio.dart index e62885a..ff15bad 100644 --- a/lib/src/builder_dio.dart +++ b/lib/src/builder_dio.dart @@ -17,7 +17,7 @@ Options buildServiceCacheOptions( forceRefresh: forceRefresh); /// build a normal cache options -Options buildCacheOptions(Duration maxAge, +Options buildCacheOptions(Duration? maxAge, {Duration? maxStale, String? primaryKey, String? subKey, From a495ef722403cc2c979f5c0d69f46be6f2171e34 Mon Sep 17 00:00:00 2001 From: pranavraagz Date: Thu, 9 Dec 2021 16:32:32 +0530 Subject: [PATCH 8/9] docs: fix minor typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 88fff9f..20f2496 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ dependencies: _dioCacheManager.deleteByPrimaryKeyAndSubKey(path, requestMethod: "GET"); ``` - **INPORTANT:** If you have additional parameters when requesting the http interface, you must take them with it, for example: + **IMPORTANT:** If you have additional parameters when requesting the http interface, you must take them with it, for example: ```dart _dio.get(_url, queryParameters: {'k': keyword}, From 9bfde57dfb7f24312d9d917f6267dcf7cdac2de3 Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Mon, 24 Jan 2022 11:08:06 +0100 Subject: [PATCH 9/9] Upgrade json_serializable --- README.md | 4 ++-- example/ios/Flutter/AppFrameworkInfo.plist | 2 +- example/ios/Flutter/Flutter.podspec | 2 +- example/ios/Podfile.lock | 4 ++-- example/ios/Runner.xcodeproj/project.pbxproj | 10 +++++----- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- pubspec.yaml | 7 +++---- 7 files changed, 15 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 20f2496..d8d1e56 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Inspired by [flutter_cache_manager](https://github.com/renefloor/flutter_cache_m ```yaml dependencies: - dio_http_cache: ^0.3.x #latest version + dio_http_cache: ^0.4.x #latest version ``` ### QuickStart @@ -100,7 +100,7 @@ dependencies: _dioCacheManager.deleteByPrimaryKeyAndSubKey(path, requestMethod: "GET"); ``` - **IMPORTANT:** If you have additional parameters when requesting the http interface, you must take them with it, for example: + **INPORTANT:** If you have additional parameters when requesting the http interface, you must take them with it, for example: ```dart _dio.get(_url, queryParameters: {'k': keyword}, diff --git a/example/ios/Flutter/AppFrameworkInfo.plist b/example/ios/Flutter/AppFrameworkInfo.plist index 9367d48..8d4492f 100644 --- a/example/ios/Flutter/AppFrameworkInfo.plist +++ b/example/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 8.0 + 9.0 diff --git a/example/ios/Flutter/Flutter.podspec b/example/ios/Flutter/Flutter.podspec index 2c4421c..663d5b2 100644 --- a/example/ios/Flutter/Flutter.podspec +++ b/example/ios/Flutter/Flutter.podspec @@ -11,7 +11,7 @@ Pod::Spec.new do |s| s.license = { :type => 'MIT' } s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' } s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s } - s.ios.deployment_target = '8.0' + s.ios.deployment_target = '9.0' # Framework linking is handled by Flutter tooling, not CocoaPods. # Add a placeholder to satisfy `s.dependency 'Flutter'` plugin podspecs. s.vendored_frameworks = 'path/to/nothing' diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 7b3fd81..0534963 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -22,10 +22,10 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/sqflite/ios" SPEC CHECKSUMS: - Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c + Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a sqflite: 6d358c025f5b867b29ed92fc697fd34924e11904 PODFILE CHECKSUM: 4f075935f8d51cabd6114ffcdb57f90115d955bd -COCOAPODS: 1.10.1 +COCOAPODS: 1.11.2 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index b069340..c9e979f 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 50; objects = { /* Begin PBXBuildFile section */ @@ -168,7 +168,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0910; + LastUpgradeCheck = 1300; ORGANIZATIONNAME = "The Chromium Authors"; TargetAttributes = { 97C146ED1CF9000F007C117D = { @@ -354,7 +354,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -431,7 +431,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -478,7 +478,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 786d6aa..f156018 100644 --- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ - Eric Kok homepage: https://github.com/hurshi/dio-http-cache environment: - sdk: '>=2.12.0 <3.0.0' + sdk: '>=2.14.0 <3.0.0' dependencies: crypto: ^3.0.1 dio: ^4.0.0 flutter: sdk: flutter - json_serializable: ^4.1.4 - json_annotation: ^4.0.1 + json_serializable: ^6.1.0 path: ^1.8.0 quiver: ^3.0.1 sqflite: ^2.0.0+3