mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
Fixed download speed display.
This commit is contained in:
@@ -139,13 +139,11 @@ 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) {
|
||||||
buffer = (configs['onResponse'] as JSInvokable)([buffer]);
|
buffer = (configs['onResponse'] as JSInvokable)([buffer]);
|
||||||
@@ -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;
|
||||||
|
|
||||||
|
@@ -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(() {});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user