TF-2628 [Part-2] Integrate loading logic to attachment item UI
This commit is contained in:
@@ -8,8 +8,10 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:model/email/attachment.dart';
|
import 'package:model/email/attachment.dart';
|
||||||
|
import 'package:tmail_ui_user/features/email/presentation/controller/single_email_controller.dart';
|
||||||
import 'package:tmail_ui_user/features/email/presentation/extensions/attachment_extension.dart';
|
import 'package:tmail_ui_user/features/email/presentation/extensions/attachment_extension.dart';
|
||||||
import 'package:tmail_ui_user/features/email/presentation/styles/attachment/attachment_item_widget_style.dart';
|
import 'package:tmail_ui_user/features/email/presentation/styles/attachment/attachment_item_widget_style.dart';
|
||||||
|
import 'package:tmail_ui_user/features/email/presentation/utils/email_utils.dart';
|
||||||
|
|
||||||
typedef OnDownloadAttachmentFileActionClick = void Function(Attachment attachment);
|
typedef OnDownloadAttachmentFileActionClick = void Function(Attachment attachment);
|
||||||
typedef OnViewAttachmentFileActionClick = void Function(Attachment attachment);
|
typedef OnViewAttachmentFileActionClick = void Function(Attachment attachment);
|
||||||
@@ -32,10 +34,20 @@ class AttachmentItemWidget extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
return Obx(
|
||||||
|
() {
|
||||||
|
final controller = Get.find<SingleEmailController>();
|
||||||
|
final attachmentsViewState = controller.attachmentsViewState;
|
||||||
|
bool isLoading = false;
|
||||||
|
if (attachment.blobId != null) {
|
||||||
|
isLoading = !EmailUtils.checkingIfAttachmentActionIsEnabled(
|
||||||
|
attachmentsViewState[attachment.blobId!]);
|
||||||
|
}
|
||||||
|
|
||||||
return Material(
|
return Material(
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () => viewAttachmentAction?.call(attachment),
|
onTap: isLoading ? null : () => viewAttachmentAction?.call(attachment),
|
||||||
customBorder: const RoundedRectangleBorder(
|
customBorder: const RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.all(Radius.circular(AttachmentItemWidgetStyle.radius))
|
borderRadius: BorderRadius.all(Radius.circular(AttachmentItemWidgetStyle.radius))
|
||||||
),
|
),
|
||||||
@@ -48,8 +60,12 @@ class AttachmentItemWidget extends StatelessWidget {
|
|||||||
width: _getMaxWidthItem(context),
|
width: _getMaxWidthItem(context),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
SvgPicture.asset(
|
isLoading
|
||||||
attachment.getIcon(_imagePaths),
|
? const SizedBox(
|
||||||
|
width: AttachmentItemWidgetStyle.iconSize,
|
||||||
|
height: AttachmentItemWidgetStyle.iconSize,
|
||||||
|
child: CircularProgressIndicator(strokeWidth: 2))
|
||||||
|
: SvgPicture.asset(attachment.getIcon(_imagePaths),
|
||||||
width: AttachmentItemWidgetStyle.iconSize,
|
width: AttachmentItemWidgetStyle.iconSize,
|
||||||
height: AttachmentItemWidgetStyle.iconSize,
|
height: AttachmentItemWidgetStyle.iconSize,
|
||||||
fit: BoxFit.fill
|
fit: BoxFit.fill
|
||||||
@@ -87,7 +103,9 @@ class AttachmentItemWidget extends StatelessWidget {
|
|||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
padding: const EdgeInsets.all(5),
|
padding: const EdgeInsets.all(5),
|
||||||
iconSize: AttachmentItemWidgetStyle.downloadIconSize,
|
iconSize: AttachmentItemWidgetStyle.downloadIconSize,
|
||||||
onTapActionCallback: () => downloadAttachmentAction?.call(attachment)
|
onTapActionCallback: isLoading
|
||||||
|
? null
|
||||||
|
: () => downloadAttachmentAction?.call(attachment)
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@@ -95,6 +113,8 @@ class AttachmentItemWidget extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
double _getMaxWidthItem(BuildContext context) {
|
double _getMaxWidthItem(BuildContext context) {
|
||||||
if (PlatformInfo.isMobile) {
|
if (PlatformInfo.isMobile) {
|
||||||
|
|||||||
+24
-4
@@ -8,8 +8,10 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:model/email/attachment.dart';
|
import 'package:model/email/attachment.dart';
|
||||||
|
import 'package:tmail_ui_user/features/email/presentation/controller/single_email_controller.dart';
|
||||||
import 'package:tmail_ui_user/features/email/presentation/extensions/attachment_extension.dart';
|
import 'package:tmail_ui_user/features/email/presentation/extensions/attachment_extension.dart';
|
||||||
import 'package:tmail_ui_user/features/email/presentation/styles/attachment/attachment_list_item_widget_styles.dart';
|
import 'package:tmail_ui_user/features/email/presentation/styles/attachment/attachment_list_item_widget_styles.dart';
|
||||||
|
import 'package:tmail_ui_user/features/email/presentation/utils/email_utils.dart';
|
||||||
import 'package:tmail_ui_user/features/email/presentation/widgets/attachment_item_widget.dart';
|
import 'package:tmail_ui_user/features/email/presentation/widgets/attachment_item_widget.dart';
|
||||||
|
|
||||||
typedef OnDownloadAttachmentFileActionClick = void Function(Attachment attachment);
|
typedef OnDownloadAttachmentFileActionClick = void Function(Attachment attachment);
|
||||||
@@ -31,16 +33,30 @@ class AttachmentListItemWidget extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
return Obx(
|
||||||
|
() {
|
||||||
|
final controller = Get.find<SingleEmailController>();
|
||||||
|
final attachmentsViewState = controller.attachmentsViewState;
|
||||||
|
bool isLoading = false;
|
||||||
|
if (attachment.blobId != null) {
|
||||||
|
isLoading = !EmailUtils.checkingIfAttachmentActionIsEnabled(
|
||||||
|
attachmentsViewState[attachment.blobId!]);
|
||||||
|
}
|
||||||
|
|
||||||
return Material(
|
return Material(
|
||||||
type: MaterialType.transparency,
|
type: MaterialType.transparency,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () => viewAttachmentAction?.call(attachment),
|
onTap: isLoading ? null : () => viewAttachmentAction?.call(attachment),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: AttachmentListItemWidgetStyle.contentPadding,
|
padding: AttachmentListItemWidgetStyle.contentPadding,
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
SvgPicture.asset(
|
isLoading
|
||||||
attachment.getIcon(_imagePaths),
|
? const SizedBox(
|
||||||
|
width: AttachmentListItemWidgetStyle.iconSize,
|
||||||
|
height: AttachmentListItemWidgetStyle.iconSize,
|
||||||
|
child: CircularProgressIndicator(strokeWidth: 2))
|
||||||
|
: SvgPicture.asset(attachment.getIcon(_imagePaths),
|
||||||
width: AttachmentListItemWidgetStyle.iconSize,
|
width: AttachmentListItemWidgetStyle.iconSize,
|
||||||
height: AttachmentListItemWidgetStyle.iconSize,
|
height: AttachmentListItemWidgetStyle.iconSize,
|
||||||
fit: BoxFit.fill
|
fit: BoxFit.fill
|
||||||
@@ -85,7 +101,9 @@ class AttachmentListItemWidget extends StatelessWidget {
|
|||||||
TMailButtonWidget.fromIcon(
|
TMailButtonWidget.fromIcon(
|
||||||
icon: _imagePaths.icDownloadAttachment,
|
icon: _imagePaths.icDownloadAttachment,
|
||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
onTapActionCallback: () => downloadAttachmentAction?.call(attachment)
|
onTapActionCallback: isLoading
|
||||||
|
? null
|
||||||
|
: () => downloadAttachmentAction?.call(attachment)
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
@@ -93,4 +111,6 @@ class AttachmentListItemWidget extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user