Fixed grey screen while file downloading

This commit is contained in:
dstark5
2024-02-05 20:17:11 +05:30
parent aac2e807f0
commit 2a2e5df118
4 changed files with 56 additions and 66 deletions

View File

@ -79,7 +79,10 @@ Future<void> 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<void> downloadFile(
onDownlaodFailed('downloaded Failed! try again...');
}
} else {
onDownlaodFailed('downloaded Failed! try again...');
onDownlaodFailed('No working mirrors available to download book!');
}
}
}

View File

@ -233,51 +233,47 @@ Future<void> 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);

View File

@ -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:

View File

@ -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