mirror of
https://github.com/dstark5/Openlib.git
synced 2025-08-06 15:18:54 +08:00
Fixed grey screen while file downloading
This commit is contained in:
@ -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'
|
'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) {
|
onReceiveProgress: (rcv, total) {
|
||||||
onProgress(rcv, total);
|
if (!(rcv.isNaN || rcv.isInfinite) &&
|
||||||
|
!(total.isNaN || total.isInfinite)) {
|
||||||
|
onProgress(rcv, total);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
deleteOnError: true,
|
deleteOnError: true,
|
||||||
cancelToken: cancelToken,
|
cancelToken: cancelToken,
|
||||||
@ -97,7 +100,7 @@ Future<void> downloadFile(
|
|||||||
onDownlaodFailed('downloaded Failed! try again...');
|
onDownlaodFailed('downloaded Failed! try again...');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
onDownlaodFailed('downloaded Failed! try again...');
|
onDownlaodFailed('No working mirrors available to download book!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -233,51 +233,47 @@ Future<void> downloadFileWidget(
|
|||||||
ref.read(downloadState.notifier).state = ProcessState.running;
|
ref.read(downloadState.notifier).state = ProcessState.running;
|
||||||
},
|
},
|
||||||
onProgress: (int rcv, int total) async {
|
onProgress: (int rcv, int total) async {
|
||||||
if (!rcv.isNaN && !total.isNaN) {
|
if (ref.read(totalFileSizeInBytes) != total) {
|
||||||
if (ref.read(totalFileSizeInBytes) != total) {
|
ref.read(totalFileSizeInBytes.notifier).state = total;
|
||||||
ref.read(totalFileSizeInBytes.notifier).state = total;
|
}
|
||||||
}
|
ref.read(downloadedFileSizeInBytes.notifier).state = rcv;
|
||||||
ref.read(downloadedFileSizeInBytes.notifier).state = rcv;
|
ref.read(downloadProgressProvider.notifier).state = rcv / total;
|
||||||
ref.read(downloadProgressProvider.notifier).state = rcv / total;
|
|
||||||
|
|
||||||
if (rcv / total == 1.0) {
|
if (rcv / total == 1.0) {
|
||||||
await ref.read(dbProvider).insert(MyBook(
|
await ref.read(dbProvider).insert(MyBook(
|
||||||
id: data.md5,
|
id: data.md5,
|
||||||
title: data.title,
|
title: data.title,
|
||||||
author: data.author,
|
author: data.author,
|
||||||
thumbnail: data.thumbnail,
|
thumbnail: data.thumbnail,
|
||||||
link: data.link,
|
link: data.link,
|
||||||
publisher: data.publisher,
|
publisher: data.publisher,
|
||||||
info: data.info,
|
info: data.info,
|
||||||
format: data.format,
|
format: data.format,
|
||||||
description: data.description));
|
description: data.description));
|
||||||
|
|
||||||
ref.read(downloadState.notifier).state = ProcessState.complete;
|
ref.read(downloadState.notifier).state = ProcessState.complete;
|
||||||
ref.read(checkSumState.notifier).state =
|
ref.read(checkSumState.notifier).state = CheckSumProcessState.running;
|
||||||
CheckSumProcessState.running;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final checkSum = await verifyFileCheckSum(
|
final checkSum = await verifyFileCheckSum(
|
||||||
md5Hash: data.md5, format: data.format);
|
md5Hash: data.md5, format: data.format);
|
||||||
if (checkSum == true) {
|
if (checkSum == true) {
|
||||||
ref.read(checkSumState.notifier).state =
|
ref.read(checkSumState.notifier).state =
|
||||||
CheckSumProcessState.success;
|
CheckSumProcessState.success;
|
||||||
} else {
|
} else {
|
||||||
ref.read(checkSumState.notifier).state =
|
|
||||||
CheckSumProcessState.failed;
|
|
||||||
}
|
|
||||||
} catch (_) {
|
|
||||||
ref.read(checkSumState.notifier).state =
|
ref.read(checkSumState.notifier).state =
|
||||||
CheckSumProcessState.failed;
|
CheckSumProcessState.failed;
|
||||||
}
|
}
|
||||||
// ignore: unused_result
|
} catch (_) {
|
||||||
ref.refresh(checkIdExists(data.md5));
|
ref.read(checkSumState.notifier).state =
|
||||||
// ignore: unused_result
|
CheckSumProcessState.failed;
|
||||||
ref.refresh(myLibraryProvider);
|
|
||||||
// ignore: use_build_context_synchronously
|
|
||||||
showSnackBar(
|
|
||||||
context: context, message: 'Book has been downloaded!');
|
|
||||||
}
|
}
|
||||||
|
// 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) {
|
cancelDownlaod: (CancelToken downloadToken) {
|
||||||
@ -309,7 +305,7 @@ class _ShowDialog extends ConsumerWidget {
|
|||||||
if (downloadProgress == 1.0 &&
|
if (downloadProgress == 1.0 &&
|
||||||
(checkSumVerifyState == CheckSumProcessState.failed ||
|
(checkSumVerifyState == CheckSumProcessState.failed ||
|
||||||
checkSumVerifyState == CheckSumProcessState.success)) {
|
checkSumVerifyState == CheckSumProcessState.success)) {
|
||||||
Future.delayed(const Duration(seconds: 2), () {
|
Future.delayed(const Duration(seconds: 1), () {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
if (checkSumVerifyState == CheckSumProcessState.failed) {
|
if (checkSumVerifyState == CheckSumProcessState.failed) {
|
||||||
_showWarningFileDialog(context);
|
_showWarningFileDialog(context);
|
||||||
|
36
pubspec.lock
36
pubspec.lock
@ -37,26 +37,26 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: cached_network_image
|
name: cached_network_image
|
||||||
sha256: "28ea9690a8207179c319965c13cd8df184d5ee721ae2ce60f398ced1219cea1f"
|
sha256: f98972704692ba679db144261172a8e20feb145636c617af0eb4022132a6797f
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.3.1"
|
version: "3.3.0"
|
||||||
cached_network_image_platform_interface:
|
cached_network_image_platform_interface:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: cached_network_image_platform_interface
|
name: cached_network_image_platform_interface
|
||||||
sha256: "9e90e78ae72caa874a323d78fa6301b3fb8fa7ea76a8f96dc5b5bf79f283bf2f"
|
sha256: "56aa42a7a01e3c9db8456d9f3f999931f1e05535b5a424271e9a38cabf066613"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.0.0"
|
version: "3.0.0"
|
||||||
cached_network_image_web:
|
cached_network_image_web:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: cached_network_image_web
|
name: cached_network_image_web
|
||||||
sha256: "42a835caa27c220d1294311ac409a43361088625a4f23c820b006dd9bffb3316"
|
sha256: "759b9a9f8f6ccbb66c185df805fac107f05730b1dab9c64626d1008cca532257"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.1"
|
version: "1.1.0"
|
||||||
characters:
|
characters:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -73,14 +73,6 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.3"
|
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:
|
cli_util:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -258,10 +250,10 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: flutter_riverpod
|
name: flutter_riverpod
|
||||||
sha256: da9591d1f8d5881628ccd5c25c40e74fc3eef50ba45e40c3905a06e1712412d5
|
sha256: "4bce556b7ecbfea26109638d5237684538d4abc509d253e6c5c4c5733b360098"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.4.9"
|
version: "2.4.10"
|
||||||
flutter_svg:
|
flutter_svg:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -292,10 +284,10 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: google_fonts
|
name: google_fonts
|
||||||
sha256: "6b6f10f0ce3c42f6552d1c70d2c28d764cf22bb487f50f66cca31dcd5194f4d6"
|
sha256: f0b8d115a13ecf827013ec9fc883390ccc0e87a96ed5347a3114cac177ef18e8
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.0.4"
|
version: "6.1.0"
|
||||||
google_nav_bar:
|
google_nav_bar:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -316,10 +308,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: http
|
name: http
|
||||||
sha256: "5895291c13fa8a3bd82e76d5627f69e0d85ca6a30dcac95c4ea19a5d555879c2"
|
sha256: a2bbf9d017fcced29139daa8ed2bba4ece450ab222871df93ca9eec6f80c34ba
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.13.6"
|
version: "1.2.0"
|
||||||
http_parser:
|
http_parser:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -564,10 +556,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: riverpod
|
name: riverpod
|
||||||
sha256: "942999ee48b899f8a46a860f1e13cee36f2f77609eb54c5b7a669bb20d550b11"
|
sha256: "548e2192eb7aeb826eb89387f814edb76594f3363e2c0bb99dd733d795ba3589"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.4.9"
|
version: "2.5.0"
|
||||||
rxdart:
|
rxdart:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -51,10 +51,9 @@ dependencies:
|
|||||||
webview_cookie_manager: ^2.0.6
|
webview_cookie_manager: ^2.0.6
|
||||||
|
|
||||||
flutter_svg: ^2.0.7
|
flutter_svg: ^2.0.7
|
||||||
google_fonts: ^4.0.4
|
google_fonts: ^6.1.0
|
||||||
|
|
||||||
cached_network_image: ^3.3.1
|
cached_network_image: 3.3.0
|
||||||
chunked_downloader: ^0.0.2
|
|
||||||
|
|
||||||
sqflite_common_ffi: ^2.3.0+2
|
sqflite_common_ffi: ^2.3.0+2
|
||||||
url_launcher: ^6.1.12
|
url_launcher: ^6.1.12
|
||||||
|
Reference in New Issue
Block a user