Skip to content

Commit

Permalink
BijlageItem download progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Netfloex committed May 6, 2022
1 parent 8166c4a commit 24fc57a
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions lib/src/ui/components/Bijlage.dart
Expand Up @@ -13,24 +13,30 @@ class BijlageItem extends StatelessWidget {
final Border border;
final ValueNotifier<DownloadState> downloadState = ValueNotifier(DownloadState.none);
final Future Function(Bron, Function(int, int)) download;
final ValueNotifier<int> downloadCount = ValueNotifier(0);

BijlageItem(
this.bijlage, {
this.onTap,
this.download,
this.border,
});

Widget build(BuildContext context) {
List<String> splittedNaam = bijlage.naam.split(".");
return Tooltip(
message: bijlage.naam,
child: ListTile(
onTap: () {
if (onTap != null) onTap();
if (download != null) {
downloadState.value = DownloadState.loading;

download(
bijlage,
(count, total) {
bijlage.downloadCount = count;
downloadCount.value = count;
if (count >= total) {
downloadState.value = DownloadState.done;
}
Expand Down Expand Up @@ -66,8 +72,13 @@ class BijlageItem extends StatelessWidget {
subtitle: bijlage.isFolder
? null
: Padding(
child: Text(
filesize(bijlage.size),
child: ValueListenableBuilder(
valueListenable: downloadCount,
builder: (context, value, child) => downloadState.value == DownloadState.loading
? Text(filesize(downloadCount.value) + "/" + filesize(bijlage.size))
: Text(
filesize(bijlage.size),
),
),
padding: EdgeInsets.only(
bottom: 5,
Expand All @@ -87,25 +98,30 @@ class BijlageItem extends StatelessWidget {
Icons.arrow_forward_ios,
size: 14,
)
: ValueListenableBuilder(
: ValueListenableBuilder<DownloadState>(
valueListenable: downloadState,
builder: (c, state, _) {
if (state == DownloadState.done) {
return Icon(
Icons.arrow_forward_ios,
size: 18,
);
}
if (state == DownloadState.none) {
return Icon(
Icons.cloud_download,
size: 22,
);
switch (state) {
case DownloadState.done:
return Icon(
Icons.arrow_forward_ios,
size: 18,
);

break;
case DownloadState.none:
return Icon(
Icons.cloud_download,
size: 22,
);
break;
case DownloadState.loading:
return CircularProgressIndicator();
break;
}
return CircularProgressIndicator();
return Container();
}),
),
message: bijlage.naam,
);
}
}

0 comments on commit 24fc57a

Please sign in to comment.