TF-3267 Implement HTML attachment preview
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
|
||||
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/responsive/responsive_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pointer_interceptor/pointer_interceptor.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 {
|
||||
const HtmlAttachmentPreviewer({
|
||||
super.key,
|
||||
required this.htmlContent,
|
||||
required this.title,
|
||||
required this.mailToClicked,
|
||||
required this.downloadAttachmentClicked,
|
||||
required this.responsiveUtils,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final String htmlContent;
|
||||
final OnMailtoClicked mailToClicked;
|
||||
final VoidCallback downloadAttachmentClicked;
|
||||
final ResponsiveUtils responsiveUtils;
|
||||
|
||||
static const double _verticalMargin = 16;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
TopBarAttachmentViewer(
|
||||
title: title,
|
||||
closeAction: popBack,
|
||||
downloadAction: 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.4,
|
||||
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
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
HtmlContentViewerOnWeb _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,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ import 'package:tmail_ui_user/features/email/domain/exceptions/download_attachme
|
||||
import 'package:tmail_ui_user/features/email/domain/state/download_attachment_for_web_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/download_attachment_for_web_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/widgets/pdf_viewer/pagination_pdf_viewer.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/widgets/pdf_viewer/top_bar_pdf_viewer.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/widgets/pdf_viewer/top_bar_attachment_viewer.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
||||
|
||||
@@ -221,8 +221,8 @@ class _PDFViewerState extends State<PDFViewer> {
|
||||
if (deviceInfo.hasData && deviceInfo.data is WebBrowserInfo) {
|
||||
browserName = (deviceInfo.data as WebBrowserInfo).browserName;
|
||||
}
|
||||
return TopBarPDFViewer(
|
||||
attachment: widget.attachment,
|
||||
return TopBarAttachmentViewer(
|
||||
title: widget.attachment.generateFileName(),
|
||||
downloadAction: () => widget.downloadAction?.call(
|
||||
viewState.bytes,
|
||||
widget.attachment.generateFileName()
|
||||
@@ -235,8 +235,8 @@ class _PDFViewerState extends State<PDFViewer> {
|
||||
}
|
||||
return child ?? const SizedBox.shrink();
|
||||
},
|
||||
child: TopBarPDFViewer(
|
||||
attachment: widget.attachment,
|
||||
child: TopBarAttachmentViewer(
|
||||
title: widget.attachment.generateFileName(),
|
||||
closeAction: () {
|
||||
_downloadAttachmentCancelToken?.cancel();
|
||||
Navigator.maybeOf(context)?.pop();
|
||||
|
||||
+5
-6
@@ -1,16 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:model/email/attachment.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
|
||||
class TopBarPDFViewer extends StatelessWidget {
|
||||
final Attachment attachment;
|
||||
class TopBarAttachmentViewer extends StatelessWidget {
|
||||
final String title;
|
||||
final VoidCallback? downloadAction;
|
||||
final VoidCallback? printAction;
|
||||
final VoidCallback? closeAction;
|
||||
|
||||
const TopBarPDFViewer({
|
||||
const TopBarAttachmentViewer({
|
||||
super.key,
|
||||
required this.attachment,
|
||||
required this.title,
|
||||
this.downloadAction,
|
||||
this.printAction,
|
||||
this.closeAction,
|
||||
@@ -40,7 +39,7 @@ class TopBarPDFViewer extends StatelessWidget {
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
attachment.generateFileName(),
|
||||
title,
|
||||
style: Theme.of(context).textTheme.labelMedium?.copyWith(
|
||||
color: Colors.white,
|
||||
fontSize: 17,
|
||||
Reference in New Issue
Block a user