diff --git a/lib/features/base/mixin/app_loader_mixin.dart b/lib/features/base/mixin/app_loader_mixin.dart index a9395e619e..f1bab3c9b0 100644 --- a/lib/features/base/mixin/app_loader_mixin.dart +++ b/lib/features/base/mixin/app_loader_mixin.dart @@ -1,8 +1,7 @@ -import 'package:core/core.dart'; +import 'package:core/presentation/extensions/color_extension.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:percent_indicator/circular_percent_indicator.dart'; import 'package:percent_indicator/linear_percent_indicator.dart'; mixin AppLoaderMixin { @@ -22,18 +21,6 @@ mixin AppLoaderMixin { backgroundColor: AppColor.colorBgMailboxSelected)); } - Widget circularPercentLoadingWidget(double percent) { - return Center( - child: CircularPercentIndicator( - percent: percent > 1.0 ? 1.0 : percent, - backgroundColor: AppColor.colorBgMailboxSelected, - progressColor: AppColor.primaryColor, - lineWidth: 3, - radius: 14, - ) - ); - } - Widget horizontalPercentLoadingWidget(double percent) { return Center( child: LinearPercentIndicator( @@ -44,12 +31,4 @@ mixin AppLoaderMixin { progressColor: AppColor.primaryColor, )); } - - Widget loadingWidgetWithSizeColor({double? size, Color? color}) { - return Center(child: SizedBox( - width: size ?? 24, - height: size ?? 24, - child: CircularProgressIndicator( - color: color ?? AppColor.colorLoading))); - } } \ No newline at end of file diff --git a/lib/features/email/data/network/email_api.dart b/lib/features/email/data/network/email_api.dart index c4e20c8e02..54912f730a 100644 --- a/lib/features/email/data/network/email_api.dart +++ b/lib/features/email/data/network/email_api.dart @@ -366,7 +366,11 @@ class EmailAPI with HandleSetErrorMixin { headers: headerParam, responseType: ResponseType.bytes), onReceiveProgress: (downloaded, total) { - final progress = (downloaded / total) * 100; + log('DownloadClient::downloadFileForWeb(): downloaded = $downloaded | total: $total'); + double progress = 0; + if (downloaded > 0 && total > downloaded) { + progress = (downloaded / total) * 100; + } log('DownloadClient::downloadFileForWeb(): progress = ${progress.round()}%'); onReceiveController.add(Right(DownloadingAttachmentForWeb( taskId, diff --git a/lib/features/mailbox_dashboard/presentation/model/download/download_task_state.dart b/lib/features/mailbox_dashboard/presentation/model/download/download_task_state.dart index 19ca745a27..4ab2331c51 100644 --- a/lib/features/mailbox_dashboard/presentation/model/download/download_task_state.dart +++ b/lib/features/mailbox_dashboard/presentation/model/download/download_task_state.dart @@ -34,7 +34,16 @@ class DownloadTaskState with EquatableMixin { ); } - double get percentDownloading => progress / 100; + double get percentDownloading { + final percent = progress / 100; + if (percent < 0) { + return 0; + } else if (percent > 1) { + return 1; + } else { + return percent; + } + } @override List get props => [taskId, attachment, progress, downloaded, total]; diff --git a/lib/features/mailbox_dashboard/presentation/widgets/download/download_task_item_widget.dart b/lib/features/mailbox_dashboard/presentation/widgets/download/download_task_item_widget.dart index af6eeca6c8..e3d3b77ae2 100644 --- a/lib/features/mailbox_dashboard/presentation/widgets/download/download_task_item_widget.dart +++ b/lib/features/mailbox_dashboard/presentation/widgets/download/download_task_item_widget.dart @@ -1,15 +1,16 @@ import 'package:byte_converter/byte_converter.dart'; +import 'package:core/presentation/extensions/color_extension.dart'; import 'package:core/presentation/resources/image_paths.dart'; import 'package:core/presentation/utils/style_utils.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:get/get.dart'; -import 'package:tmail_ui_user/features/base/mixin/app_loader_mixin.dart'; +import 'package:percent_indicator/circular_percent_indicator.dart'; import 'package:tmail_ui_user/features/email/presentation/extensions/attachment_extension.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/download/download_task_state.dart'; -class DownloadTaskItemWidget extends StatelessWidget with AppLoaderMixin { +class DownloadTaskItemWidget extends StatelessWidget { final DownloadTaskState taskState; @@ -40,7 +41,17 @@ class DownloadTaskItemWidget extends StatelessWidget with AppLoaderMixin { width: 16, height: 16, fit: BoxFit.fill), - circularPercentLoadingWidget(taskState.percentDownloading) + Center( + child: taskState.percentDownloading == 0 + ? const CircularProgressIndicator(color: AppColor.primaryColor, strokeWidth: 3) + : CircularPercentIndicator( + percent: taskState.percentDownloading, + backgroundColor: AppColor.colorBgMailboxSelected, + progressColor: AppColor.primaryColor, + lineWidth: 3, + radius: 14, + ) + ) ]), ), const SizedBox(width: 12),