TF-2172 Add DraggableAttachmentItem widget

(cherry picked from commit 1d10593e6f65a5a8abc9f57b1baacfc460298280)
This commit is contained in:
dab246
2023-10-02 15:09:05 +07:00
committed by Dat H. Pham
parent 5b8c45586b
commit 7fe69aeab6
6 changed files with 254 additions and 59 deletions
@@ -1,6 +1,7 @@
import 'package:core/presentation/extensions/color_extension.dart';
import 'package:core/presentation/resources/image_paths.dart';
import 'package:core/presentation/views/button/tmail_button_widget.dart';
import 'package:core/utils/platform_info.dart';
import 'package:filesize/filesize.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
@@ -9,20 +10,23 @@ import 'package:model/email/attachment.dart';
import 'package:model/extensions/list_attachment_extension.dart';
import 'package:tmail_ui_user/features/base/widget/custom_scroll_behavior.dart';
import 'package:tmail_ui_user/features/email/presentation/styles/email_attachments_styles.dart';
import 'package:tmail_ui_user/features/email/presentation/widgets/attachment_file_tile_builder.dart';
import 'package:tmail_ui_user/features/email/presentation/widgets/attachment_item_widget.dart';
import 'package:tmail_ui_user/features/email/presentation/widgets/draggable_attachment_item_widget.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
typedef OnDownloadAttachmentActionCallback = Function(BuildContext context, Attachment attachment);
class EmailAttachmentsWidget extends StatefulWidget {
final List<Attachment> attachments;
final OnDownloadAttachmentActionCallback? onDownloadAttachmentActionCallback;
final OnDragAttachmentStarted? onDragStarted;
final OnDragAttachmentEnd? onDragEnd;
final OnDownloadAttachmentFileActionClick? downloadAttachmentAction;
const EmailAttachmentsWidget({
super.key,
required this.attachments,
this.onDownloadAttachmentActionCallback
this.onDragStarted,
this.onDragEnd,
this.downloadAttachmentAction
});
@override
@@ -95,10 +99,21 @@ class _EmailAttachmentsWidgetState extends State<EmailAttachmentsWidget> {
Wrap(
runSpacing: EmailAttachmentsStyles.listSpace,
children: widget.attachments
.map((attachment) => AttachmentFileTileBuilder(
attachment,
onDownloadAttachmentFileActionClick: (attachment) => widget.onDownloadAttachmentActionCallback?.call(context, attachment)
))
.map((attachment) {
if (PlatformInfo.isWeb) {
return DraggableAttachmentItemWidget(
attachment: attachment,
onDragStarted: widget.onDragStarted,
onDragEnd: widget.onDragEnd,
downloadAttachmentAction: widget.downloadAttachmentAction,
);
} else {
return AttachmentItemWidget(
attachment: attachment,
downloadAttachmentAction: widget.downloadAttachmentAction
);
}
})
.toList()
)
else
@@ -111,10 +126,19 @@ class _EmailAttachmentsWidgetState extends State<EmailAttachmentsWidget> {
scrollDirection: Axis.horizontal,
itemCount: widget.attachments.length,
itemBuilder: (context, index) {
return AttachmentFileTileBuilder(
widget.attachments[index],
onDownloadAttachmentFileActionClick: (attachment) => widget.onDownloadAttachmentActionCallback?.call(context, attachment)
);
if (PlatformInfo.isWeb) {
return DraggableAttachmentItemWidget(
attachment: widget.attachments[index],
onDragStarted: widget.onDragStarted,
onDragEnd: widget.onDragEnd,
downloadAttachmentAction: widget.downloadAttachmentAction
);
} else {
return AttachmentItemWidget(
attachment: widget.attachments[index],
downloadAttachmentAction: widget.downloadAttachmentAction
);
}
}
),
)