Fixed download speed display.

This commit is contained in:
2025-02-20 13:16:09 +08:00
parent bd5d10e919
commit edc2cb066b
3 changed files with 22 additions and 8 deletions

View File

@@ -509,7 +509,7 @@ class LocalManager with ChangeNotifier {
var dir = Directory(FilePath.join(path, c.directory)); var dir = Directory(FilePath.join(path, c.directory));
dir.deleteIgnoreError(recursive: true); dir.deleteIgnoreError(recursive: true);
} }
// Deleting a local comic means that it's nolonger available, thus both favorite and history should be deleted. // Deleting a local comic means that it's no longer available, thus both favorite and history should be deleted.
if (c.comicType == ComicType.local) { if (c.comicType == ComicType.local) {
if (HistoryManager().find(c.id, c.comicType) != null) { if (HistoryManager().find(c.id, c.comicType) != null) {
HistoryManager().remove(c.id, c.comicType); HistoryManager().remove(c.id, c.comicType);

View File

@@ -139,12 +139,10 @@ class ImageDownloader {
var buffer = <int>[]; var buffer = <int>[];
await for (var data in stream) { await for (var data in stream) {
buffer.addAll(data); buffer.addAll(data);
if (expectedBytes != null) { yield ImageDownloadProgress(
yield ImageDownloadProgress( currentBytes: buffer.length,
currentBytes: buffer.length, totalBytes: expectedBytes,
totalBytes: expectedBytes, );
);
}
} }
if (configs['onResponse'] is JSInvokable) { if (configs['onResponse'] is JSInvokable) {
@@ -194,7 +192,7 @@ class ImageDownloader {
class ImageDownloadProgress { class ImageDownloadProgress {
final int currentBytes; final int currentBytes;
final int totalBytes; final int? totalBytes;
final Uint8List? imageBytes; final Uint8List? imageBytes;

View File

@@ -15,6 +15,15 @@ class DownloadingPage extends StatefulWidget {
} }
class _DownloadingPageState extends State<DownloadingPage> { class _DownloadingPageState extends State<DownloadingPage> {
DownloadTask? firstTask;
@override
void didChangeDependencies() {
super.didChangeDependencies();
firstTask = LocalManager().downloadingTasks.firstOrNull;
firstTask?.addListener(update);
}
@override @override
void initState() { void initState() {
LocalManager().addListener(update); LocalManager().addListener(update);
@@ -24,10 +33,17 @@ class _DownloadingPageState extends State<DownloadingPage> {
@override @override
void dispose() { void dispose() {
LocalManager().removeListener(update); LocalManager().removeListener(update);
firstTask?.removeListener(update);
super.dispose(); super.dispose();
} }
void update() { void update() {
var currentFirstTask = LocalManager().downloadingTasks.firstOrNull;
if (currentFirstTask != firstTask) {
firstTask?.removeListener(update);
firstTask = currentFirstTask;
firstTask?.addListener(update);
}
if(mounted) { if(mounted) {
setState(() {}); setState(() {});
} }