diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b63ac3..c059078 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. +## [0.2.12] + * Minor network related bug fixes, fixing issue [#105](https://github.com/incrediblezayed/file_saver/issues/105) + * & Issue [#106](https://github.com/incrediblezayed/file_saver/issues/106) + ## [0.2.11] * Merged PR [#87](https://github.com/incrediblezayed/file_saver/pull/87) for backward compatibility with the older versions of java diff --git a/android/build.gradle b/android/build.gradle index bec8c14..045ef30 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -39,6 +39,10 @@ android { targetCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8 } + + kotlinOptions { + jvmTarget = '1.8' + } } diff --git a/example/pubspec.lock b/example/pubspec.lock index 34faaa8..28488e4 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -127,7 +127,7 @@ packages: path: ".." relative: true source: path - version: "0.2.10" + version: "0.2.11" flutter: dependency: "direct main" description: flutter @@ -175,6 +175,30 @@ packages: url: "https://pub.dev" source: hosted version: "0.7.1" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + url: "https://pub.dev" + source: hosted + version: "10.0.0" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + url: "https://pub.dev" + source: hosted + version: "2.0.1" lints: dependency: transitive description: @@ -195,10 +219,10 @@ packages: dependency: transitive description: name: material_color_utilities - sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" url: "https://pub.dev" source: hosted - version: "0.5.0" + version: "0.8.0" meta: dependency: transitive description: @@ -392,10 +416,10 @@ packages: dependency: transitive description: name: test_api - sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" url: "https://pub.dev" source: hosted - version: "0.7.0" + version: "0.6.1" typed_data: dependency: transitive description: @@ -412,14 +436,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" - web: + vm_service: dependency: transitive description: - name: web - sha256: "4188706108906f002b3a293509234588823c8c979dc83304e229ff400c996b05" + name: vm_service + sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 url: "https://pub.dev" source: hosted - version: "0.4.2" + version: "13.0.0" win32: dependency: transitive description: diff --git a/lib/src/models/link_details.dart b/lib/src/models/link_details.dart index e04f6b4..09052b8 100644 --- a/lib/src/models/link_details.dart +++ b/lib/src/models/link_details.dart @@ -1,4 +1,5 @@ // ignore_for_file: public_member_api_docs, sort_constructors_first +import 'package:dio/dio.dart'; import 'package:flutter/foundation.dart'; class LinkDetails { @@ -6,41 +7,41 @@ class LinkDetails { final String method; final Object? body; final Map? headers; + final Map? queryParameters; + final ResponseType responseType; LinkDetails({ required this.link, this.headers, this.body, this.method = 'GET', + this.queryParameters, + this.responseType = ResponseType.bytes, }); - LinkDetails copyWith({ - String? link, - String? method, - Object? body, - Map? headers, - }) { - return LinkDetails( - link: link ?? this.link, - body: body ?? this.body, - method: method ?? this.method, - headers: headers ?? this.headers, - ); - } - - @override - String toString() => 'LinkDetails(link: $link, headers: $headers)'; - @override bool operator ==(covariant LinkDetails other) { if (identical(this, other)) return true; return other.link == link && - mapEquals(other.headers, headers) && other.method == method && - other.body == body; + other.body == body && + mapEquals(other.headers, headers) && + mapEquals(other.queryParameters, queryParameters) && + other.responseType == responseType; } @override - int get hashCode => - link.hashCode ^ headers.hashCode ^ method.hashCode ^ body.hashCode; + int get hashCode { + return link.hashCode ^ + method.hashCode ^ + body.hashCode ^ + headers.hashCode ^ + queryParameters.hashCode ^ + responseType.hashCode; + } + + @override + String toString() { + return 'LinkDetails(link: $link, method: $method, body: $body, headers: $headers, queryParameters: $queryParameters, responseType: $responseType)'; + } } diff --git a/lib/src/utils/helpers.dart b/lib/src/utils/helpers.dart index 4050167..32e9110 100644 --- a/lib/src/utils/helpers.dart +++ b/lib/src/utils/helpers.dart @@ -1,3 +1,4 @@ +import 'dart:convert'; import 'dart:developer'; import 'dart:io'; @@ -44,12 +45,24 @@ class Helpers { ); Response response = await dio.request( link.link, + data: link.body, + queryParameters: link.queryParameters, ); if (transformDioResponse != null) { return transformDioResponse(response.data); + } else { + if (response.data is Uint8List) { + return response.data; + } else if (response.data is List) { + return Uint8List.fromList(response.data); + } else if (response.data is String) { + return utf8.encode(response.data); + } else { + throw Exception( + 'Invalid data type, if you have a different response type, then provide the transformDioResponse function', + ); + } } - Uint8List bytes = response.data; - return bytes; } ///This method provides default downloads directory for saving the file for Android, iOS, Linux, Windows, macOS diff --git a/pubspec.lock b/pubspec.lock index 1fd65b0..e8bf351 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -45,10 +45,10 @@ packages: dependency: "direct main" description: name: dio - sha256: "797e1e341c3dd2f69f2dad42564a6feff3bfb87187d05abb93b9609e6f1645c3" + sha256: "49af28382aefc53562459104f64d16b9dfd1e8ef68c862d5af436cc8356ce5a8" url: "https://pub.dev" source: hosted - version: "5.4.0" + version: "5.4.1" fake_async: dependency: transitive description: @@ -96,6 +96,30 @@ packages: url: "https://pub.dev" source: hosted version: "4.0.2" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + url: "https://pub.dev" + source: hosted + version: "10.0.0" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + url: "https://pub.dev" + source: hosted + version: "2.0.1" lints: dependency: transitive description: @@ -116,10 +140,10 @@ packages: dependency: transitive description: name: material_color_utilities - sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" url: "https://pub.dev" source: hosted - version: "0.5.0" + version: "0.8.0" meta: dependency: transitive description: @@ -249,10 +273,10 @@ packages: dependency: transitive description: name: test_api - sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" url: "https://pub.dev" source: hosted - version: "0.7.0" + version: "0.6.1" typed_data: dependency: transitive description: @@ -269,14 +293,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" - web: + vm_service: dependency: transitive description: - name: web - sha256: "4188706108906f002b3a293509234588823c8c979dc83304e229ff400c996b05" + name: vm_service + sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 url: "https://pub.dev" source: hosted - version: "0.4.2" + version: "13.0.0" win32: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 73cd8f0..39f514a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: file_saver description: >- This package will help you save file with a single method on any platform including macOS, iOS, Android, Windows, Web, Linux. -version: 0.2.11 +version: 0.2.12 repository: https://github.com/incrediblezayed/file_saver homepage: https://hassanansari.dev @@ -18,7 +18,7 @@ dependencies: path_provider: ^2.1.2 path_provider_windows: ^2.2.1 path_provider_linux: ^2.2.1 - dio: ^5.4.0 + dio: ^5.4.1 dev_dependencies: flutter_lints: ^3.0.1