TF-3267 Implement HTML attachment preview

This commit is contained in:
DatDang
2024-12-06 10:07:53 +07:00
committed by Dat H. Pham
parent 3ddb81a8c4
commit ac91cae0db
22 changed files with 558 additions and 18 deletions
@@ -47,4 +47,9 @@ extension MediaTypeExtension on MediaType {
fileName?.endsWith(Constant.pdfExtension) == true);
bool get isEMLFile => mimeType == Constant.emlMimeType;
bool isHTMLFile({required String? fileName}) =>
mimeType == Constant.textHtmlMimeType ||
(mimeType == Constant.octetStreamMimeType &&
fileName?.endsWith(Constant.htmlExtension) == true);
}
@@ -20,6 +20,9 @@ class StandardizeHtmlSanitizingTransformers extends TextTransformer {
'style',
'body',
'section',
'nav',
'main',
'footer',
];
const StandardizeHtmlSanitizingTransformers();
@@ -12,6 +12,7 @@ import 'package:flutter/cupertino.dart';
import 'package:universal_html/html.dart' as html;
typedef OnClickHyperLinkAction = Function(Uri?);
typedef OnMailtoClicked = void Function(Uri? uri);
class HtmlContentViewerOnWeb extends StatefulWidget {
@@ -21,13 +22,15 @@ class HtmlContentViewerOnWeb extends StatefulWidget {
final TextDirection? direction;
/// Handler for mailto: links
final Function(Uri?)? mailtoDelegate;
final OnMailtoClicked? mailtoDelegate;
final OnClickHyperLinkAction? onClickHyperLinkAction;
// if widthContent is bigger than width of htmlContent, set this to true let widget able to resize to width of htmlContent
// if widthContent is bigger than width of htmlContent, set this to true let widget able to resize to width of htmlContent
final bool allowResizeToDocumentSize;
final bool keepWidthWhileLoading;
const HtmlContentViewerOnWeb({
Key? key,
required this.contentHtml,
@@ -37,6 +40,7 @@ class HtmlContentViewerOnWeb extends StatefulWidget {
this.mailtoDelegate,
this.direction,
this.onClickHyperLinkAction,
this.keepWidthWhileLoading = false,
}) : super(key: key);
@override
@@ -99,7 +103,7 @@ class _HtmlContentViewerOnWebState extends State<HtmlContentViewerOnWeb> {
}
}
if (data['type'] != null && data['type'].contains('toDart: htmlWidth')) {
if (data['type'] != null && data['type'].contains('toDart: htmlWidth') && !widget.keepWidthWhileLoading) {
final docWidth = data['width'] ?? _actualWidth;
if (docWidth != null && mounted) {
if (docWidth > _minWidth && widget.allowResizeToDocumentSize) {