Hotfix Html attachment previewer on mobile (#3442)

This commit is contained in:
Dat Dang
2025-01-23 22:25:30 +07:00
committed by Dat H. Pham
parent fb3f4d10a5
commit 56955b2cfe
4 changed files with 102 additions and 46 deletions
@@ -276,7 +276,8 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
htmlContent: success.sanitizedHtmlContent,
mailToClicked: openMailToLink,
downloadAttachmentClicked: () {
downloadAttachmentForWeb(success.attachment);
if (currentContext == null || attachments.isEmpty) return;
handleDownloadAttachmentAction(currentContext!, success.attachment);
},
responsiveUtils: responsiveUtils,
));
@@ -1,14 +1,16 @@
import 'package:core/presentation/utils/responsive_utils.dart';
import 'package:core/presentation/views/html_viewer/html_content_viewer_on_web_widget.dart';
import 'package:core/presentation/views/html_viewer/html_content_viewer_widget.dart';
import 'package:core/presentation/views/responsive/responsive_widget.dart';
import 'package:core/utils/platform_info.dart';
import 'package:flutter/material.dart';
import 'package:pointer_interceptor/pointer_interceptor.dart';
import 'package:tmail_ui_user/features/base/isolate/background_isolate_binary_messenger/background_isolate_binary_messenger_mobile.dart';
import 'package:tmail_ui_user/features/email/presentation/widgets/pdf_viewer/top_bar_attachment_viewer.dart';
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
import 'package:tmail_ui_user/main/utils/app_utils.dart';
class HtmlAttachmentPreviewer extends StatelessWidget {
class HtmlAttachmentPreviewer extends StatefulWidget {
const HtmlAttachmentPreviewer({
super.key,
required this.htmlContent,
@@ -24,46 +26,61 @@ class HtmlAttachmentPreviewer extends StatelessWidget {
final VoidCallback downloadAttachmentClicked;
final ResponsiveUtils responsiveUtils;
@override
State<HtmlAttachmentPreviewer> createState() => _HtmlAttachmentPreviewerState();
}
class _HtmlAttachmentPreviewerState extends State<HtmlAttachmentPreviewer> {
final focusNode = FocusNode();
static const double _verticalMargin = 16;
@override
void dispose() {
focusNode.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Column(
final child = Column(
children: [
TopBarAttachmentViewer(
title: title,
title: widget.title,
closeAction: popBack,
downloadAction: downloadAttachmentClicked,
downloadAction: widget.downloadAttachmentClicked,
),
Expanded(
child: LayoutBuilder(
builder: (context, constraints) {
return SingleChildScrollView(
child: GestureDetector(
onTap: popBack,
child: PointerInterceptor(
child: ColoredBox(
color: Colors.transparent,
child: Center(
child: Container(
margin: const EdgeInsets.symmetric(vertical: _verticalMargin),
color: Colors.white,
child: ResponsiveWidget(
responsiveUtils: responsiveUtils,
desktop: _buildHtmlViewerWith(
context,
width: constraints.maxWidth * 0.8,
height: constraints.maxHeight - _verticalMargin * 2
),
tablet: _buildHtmlViewerWith(
context,
width: constraints.maxWidth * 0.8,
height: constraints.maxHeight - _verticalMargin * 2
),
mobile: _buildHtmlViewerWith(
context,
width: constraints.maxWidth,
height: constraints.maxHeight - _verticalMargin * 2
return Center(
child: SingleChildScrollView(
child: GestureDetector(
onTap: popBack,
child: PointerInterceptor(
child: ColoredBox(
color: Colors.transparent,
child: Center(
child: Container(
margin: const EdgeInsets.symmetric(vertical: _verticalMargin),
color: Colors.white,
child: ResponsiveWidget(
responsiveUtils: widget.responsiveUtils,
desktop: _buildHtmlViewerWith(
context,
width: constraints.maxWidth * 0.8,
height: constraints.maxHeight - _verticalMargin * 2
),
tablet: _buildHtmlViewerWith(
context,
width: constraints.maxWidth * 0.8,
height: constraints.maxHeight - _verticalMargin * 2
),
mobile: _buildHtmlViewerWith(
context,
width: constraints.maxWidth,
height: constraints.maxHeight - _verticalMargin * 2
),
),
),
),
@@ -77,23 +94,46 @@ class HtmlAttachmentPreviewer extends StatelessWidget {
),
],
);
if (PlatformInfo.isMobile) return child;
return KeyboardListener(
focusNode: focusNode,
onKeyEvent: (event) {
if (!mounted) return;
if (event is KeyDownEvent && event.logicalKey == LogicalKeyboardKey.escape) {
popBack();
}
},
child: child,
);
}
HtmlContentViewerOnWeb _buildHtmlViewerWith(
Widget _buildHtmlViewerWith(
BuildContext context, {
required double width,
required double height,
}) {
return HtmlContentViewerOnWeb(
contentHtml: htmlContent,
widthContent: width,
heightContent: height,
direction: AppUtils.getCurrentDirection(context),
mailtoDelegate: (uri) {
popBack();
mailToClicked(uri);
},
keepWidthWhileLoading: true,
);
return PlatformInfo.isWeb
? HtmlContentViewerOnWeb(
contentHtml: widget.htmlContent,
widthContent: width,
heightContent: height,
direction: AppUtils.getCurrentDirection(context),
mailtoDelegate: (uri) {
popBack();
widget.mailToClicked(uri);
},
keepWidthWhileLoading: true,
)
: HtmlContentViewer(
contentHtml: widget.htmlContent,
initialWidth: width,
direction: AppUtils.getCurrentDirection(context),
onMailtoDelegateAction: (uri) async {
widget.mailToClicked(uri);
},
keepWidthWhileLoading: true,
);
}
}