From 2a2e5df1186b4f7e49b5f089d6b4afffb33c6a11 Mon Sep 17 00:00:00 2001 From: dstark5 Date: Mon, 5 Feb 2024 20:17:11 +0530 Subject: [PATCH] Fixed grey screen while file downloading --- lib/services/download_file.dart | 7 +++- lib/ui/book_info_page.dart | 74 ++++++++++++++++----------------- pubspec.lock | 36 +++++++--------- pubspec.yaml | 5 +-- 4 files changed, 56 insertions(+), 66 deletions(-) diff --git a/lib/services/download_file.dart b/lib/services/download_file.dart index a9365b0..04b64cc 100644 --- a/lib/services/download_file.dart +++ b/lib/services/download_file.dart @@ -79,7 +79,10 @@ Future downloadFile( 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36' }), onReceiveProgress: (rcv, total) { - onProgress(rcv, total); + if (!(rcv.isNaN || rcv.isInfinite) && + !(total.isNaN || total.isInfinite)) { + onProgress(rcv, total); + } }, deleteOnError: true, cancelToken: cancelToken, @@ -97,7 +100,7 @@ Future downloadFile( onDownlaodFailed('downloaded Failed! try again...'); } } else { - onDownlaodFailed('downloaded Failed! try again...'); + onDownlaodFailed('No working mirrors available to download book!'); } } } diff --git a/lib/ui/book_info_page.dart b/lib/ui/book_info_page.dart index 250555f..32ffcc8 100644 --- a/lib/ui/book_info_page.dart +++ b/lib/ui/book_info_page.dart @@ -233,51 +233,47 @@ Future downloadFileWidget( ref.read(downloadState.notifier).state = ProcessState.running; }, onProgress: (int rcv, int total) async { - if (!rcv.isNaN && !total.isNaN) { - if (ref.read(totalFileSizeInBytes) != total) { - ref.read(totalFileSizeInBytes.notifier).state = total; - } - ref.read(downloadedFileSizeInBytes.notifier).state = rcv; - ref.read(downloadProgressProvider.notifier).state = rcv / total; + if (ref.read(totalFileSizeInBytes) != total) { + ref.read(totalFileSizeInBytes.notifier).state = total; + } + ref.read(downloadedFileSizeInBytes.notifier).state = rcv; + ref.read(downloadProgressProvider.notifier).state = rcv / total; - if (rcv / total == 1.0) { - await ref.read(dbProvider).insert(MyBook( - id: data.md5, - title: data.title, - author: data.author, - thumbnail: data.thumbnail, - link: data.link, - publisher: data.publisher, - info: data.info, - format: data.format, - description: data.description)); + if (rcv / total == 1.0) { + await ref.read(dbProvider).insert(MyBook( + id: data.md5, + title: data.title, + author: data.author, + thumbnail: data.thumbnail, + link: data.link, + publisher: data.publisher, + info: data.info, + format: data.format, + description: data.description)); - ref.read(downloadState.notifier).state = ProcessState.complete; - ref.read(checkSumState.notifier).state = - CheckSumProcessState.running; + ref.read(downloadState.notifier).state = ProcessState.complete; + ref.read(checkSumState.notifier).state = CheckSumProcessState.running; - try { - final checkSum = await verifyFileCheckSum( - md5Hash: data.md5, format: data.format); - if (checkSum == true) { - ref.read(checkSumState.notifier).state = - CheckSumProcessState.success; - } else { - ref.read(checkSumState.notifier).state = - CheckSumProcessState.failed; - } - } catch (_) { + try { + final checkSum = await verifyFileCheckSum( + md5Hash: data.md5, format: data.format); + if (checkSum == true) { + ref.read(checkSumState.notifier).state = + CheckSumProcessState.success; + } else { ref.read(checkSumState.notifier).state = CheckSumProcessState.failed; } - // ignore: unused_result - ref.refresh(checkIdExists(data.md5)); - // ignore: unused_result - ref.refresh(myLibraryProvider); - // ignore: use_build_context_synchronously - showSnackBar( - context: context, message: 'Book has been downloaded!'); + } catch (_) { + ref.read(checkSumState.notifier).state = + CheckSumProcessState.failed; } + // ignore: unused_result + ref.refresh(checkIdExists(data.md5)); + // ignore: unused_result + ref.refresh(myLibraryProvider); + // ignore: use_build_context_synchronously + showSnackBar(context: context, message: 'Book has been downloaded!'); } }, cancelDownlaod: (CancelToken downloadToken) { @@ -309,7 +305,7 @@ class _ShowDialog extends ConsumerWidget { if (downloadProgress == 1.0 && (checkSumVerifyState == CheckSumProcessState.failed || checkSumVerifyState == CheckSumProcessState.success)) { - Future.delayed(const Duration(seconds: 2), () { + Future.delayed(const Duration(seconds: 1), () { Navigator.of(context).pop(); if (checkSumVerifyState == CheckSumProcessState.failed) { _showWarningFileDialog(context); diff --git a/pubspec.lock b/pubspec.lock index 3d598e6..a02901f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -37,26 +37,26 @@ packages: dependency: "direct main" description: name: cached_network_image - sha256: "28ea9690a8207179c319965c13cd8df184d5ee721ae2ce60f398ced1219cea1f" + sha256: f98972704692ba679db144261172a8e20feb145636c617af0eb4022132a6797f url: "https://pub.dev" source: hosted - version: "3.3.1" + version: "3.3.0" cached_network_image_platform_interface: dependency: transitive description: name: cached_network_image_platform_interface - sha256: "9e90e78ae72caa874a323d78fa6301b3fb8fa7ea76a8f96dc5b5bf79f283bf2f" + sha256: "56aa42a7a01e3c9db8456d9f3f999931f1e05535b5a424271e9a38cabf066613" url: "https://pub.dev" source: hosted - version: "4.0.0" + version: "3.0.0" cached_network_image_web: dependency: transitive description: name: cached_network_image_web - sha256: "42a835caa27c220d1294311ac409a43361088625a4f23c820b006dd9bffb3316" + sha256: "759b9a9f8f6ccbb66c185df805fac107f05730b1dab9c64626d1008cca532257" url: "https://pub.dev" source: hosted - version: "1.1.1" + version: "1.1.0" characters: dependency: transitive description: @@ -73,14 +73,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.3" - chunked_downloader: - dependency: "direct main" - description: - name: chunked_downloader - sha256: "7fe3a37a0c7fb1d41f3f922c30937fdccae2647b6f6f71778bffcf4823048754" - url: "https://pub.dev" - source: hosted - version: "0.0.2" cli_util: dependency: transitive description: @@ -258,10 +250,10 @@ packages: dependency: "direct main" description: name: flutter_riverpod - sha256: da9591d1f8d5881628ccd5c25c40e74fc3eef50ba45e40c3905a06e1712412d5 + sha256: "4bce556b7ecbfea26109638d5237684538d4abc509d253e6c5c4c5733b360098" url: "https://pub.dev" source: hosted - version: "2.4.9" + version: "2.4.10" flutter_svg: dependency: "direct main" description: @@ -292,10 +284,10 @@ packages: dependency: "direct main" description: name: google_fonts - sha256: "6b6f10f0ce3c42f6552d1c70d2c28d764cf22bb487f50f66cca31dcd5194f4d6" + sha256: f0b8d115a13ecf827013ec9fc883390ccc0e87a96ed5347a3114cac177ef18e8 url: "https://pub.dev" source: hosted - version: "4.0.4" + version: "6.1.0" google_nav_bar: dependency: "direct main" description: @@ -316,10 +308,10 @@ packages: dependency: transitive description: name: http - sha256: "5895291c13fa8a3bd82e76d5627f69e0d85ca6a30dcac95c4ea19a5d555879c2" + sha256: a2bbf9d017fcced29139daa8ed2bba4ece450ab222871df93ca9eec6f80c34ba url: "https://pub.dev" source: hosted - version: "0.13.6" + version: "1.2.0" http_parser: dependency: transitive description: @@ -564,10 +556,10 @@ packages: dependency: transitive description: name: riverpod - sha256: "942999ee48b899f8a46a860f1e13cee36f2f77609eb54c5b7a669bb20d550b11" + sha256: "548e2192eb7aeb826eb89387f814edb76594f3363e2c0bb99dd733d795ba3589" url: "https://pub.dev" source: hosted - version: "2.4.9" + version: "2.5.0" rxdart: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index f7276fc..d1ead7d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -51,10 +51,9 @@ dependencies: webview_cookie_manager: ^2.0.6 flutter_svg: ^2.0.7 - google_fonts: ^4.0.4 + google_fonts: ^6.1.0 - cached_network_image: ^3.3.1 - chunked_downloader: ^0.0.2 + cached_network_image: 3.3.0 sqflite_common_ffi: ^2.3.0+2 url_launcher: ^6.1.12