Hotfix Html attachment previewer on mobile (#3442)
This commit is contained in:
@@ -294,7 +294,7 @@ class _HtmlContentViewerOnWebState extends State<HtmlContentViewerOnWeb> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return LayoutBuilder(builder: (context, constraint) {
|
return LayoutBuilder(builder: (context, constraint) {
|
||||||
minHeight = math.max(constraint.maxHeight, minHeight);
|
minHeight = math.max(constraint.maxHeight, minHeight);
|
||||||
return Stack(
|
final child = Stack(
|
||||||
children: [
|
children: [
|
||||||
if (_htmlData?.isNotEmpty == false)
|
if (_htmlData?.isNotEmpty == false)
|
||||||
const SizedBox.shrink()
|
const SizedBox.shrink()
|
||||||
@@ -332,6 +332,13 @@ class _HtmlContentViewerOnWebState extends State<HtmlContentViewerOnWeb> {
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!widget.keepWidthWhileLoading) return child;
|
||||||
|
|
||||||
|
return SizedBox(
|
||||||
|
width: _actualWidth,
|
||||||
|
child: child,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ class HtmlContentViewer extends StatefulWidget {
|
|||||||
final String contentHtml;
|
final String contentHtml;
|
||||||
final double? initialWidth;
|
final double? initialWidth;
|
||||||
final TextDirection? direction;
|
final TextDirection? direction;
|
||||||
|
final bool keepWidthWhileLoading;
|
||||||
|
|
||||||
final OnLoadWidthHtmlViewerAction? onLoadWidthHtmlViewer;
|
final OnLoadWidthHtmlViewerAction? onLoadWidthHtmlViewer;
|
||||||
final OnMailtoDelegateAction? onMailtoDelegateAction;
|
final OnMailtoDelegateAction? onMailtoDelegateAction;
|
||||||
@@ -37,6 +38,7 @@ class HtmlContentViewer extends StatefulWidget {
|
|||||||
required this.contentHtml,
|
required this.contentHtml,
|
||||||
this.initialWidth,
|
this.initialWidth,
|
||||||
this.direction,
|
this.direction,
|
||||||
|
this.keepWidthWhileLoading = false,
|
||||||
this.onLoadWidthHtmlViewer,
|
this.onLoadWidthHtmlViewer,
|
||||||
this.onMailtoDelegateAction,
|
this.onMailtoDelegateAction,
|
||||||
this.onScrollHorizontalEnd,
|
this.onScrollHorizontalEnd,
|
||||||
@@ -109,7 +111,7 @@ class _HtmlContentViewState extends State<HtmlContentViewer> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Stack(children: [
|
final child = Stack(children: [
|
||||||
if (_htmlData == null)
|
if (_htmlData == null)
|
||||||
const SizedBox.shrink()
|
const SizedBox.shrink()
|
||||||
else
|
else
|
||||||
@@ -138,6 +140,12 @@ class _HtmlContentViewState extends State<HtmlContentViewer> {
|
|||||||
}
|
}
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if (!widget.keepWidthWhileLoading) return child;
|
||||||
|
return SizedBox(
|
||||||
|
width: widget.initialWidth,
|
||||||
|
child: child,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onWebViewCreated(InAppWebViewController controller) async {
|
void _onWebViewCreated(InAppWebViewController controller) async {
|
||||||
|
|||||||
@@ -276,7 +276,8 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
|||||||
htmlContent: success.sanitizedHtmlContent,
|
htmlContent: success.sanitizedHtmlContent,
|
||||||
mailToClicked: openMailToLink,
|
mailToClicked: openMailToLink,
|
||||||
downloadAttachmentClicked: () {
|
downloadAttachmentClicked: () {
|
||||||
downloadAttachmentForWeb(success.attachment);
|
if (currentContext == null || attachments.isEmpty) return;
|
||||||
|
handleDownloadAttachmentAction(currentContext!, success.attachment);
|
||||||
},
|
},
|
||||||
responsiveUtils: responsiveUtils,
|
responsiveUtils: responsiveUtils,
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
|
|
||||||
import 'package:core/presentation/utils/responsive_utils.dart';
|
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_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/presentation/views/responsive/responsive_widget.dart';
|
||||||
|
import 'package:core/utils/platform_info.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:pointer_interceptor/pointer_interceptor.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/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/routes/route_navigation.dart';
|
||||||
import 'package:tmail_ui_user/main/utils/app_utils.dart';
|
import 'package:tmail_ui_user/main/utils/app_utils.dart';
|
||||||
|
|
||||||
class HtmlAttachmentPreviewer extends StatelessWidget {
|
class HtmlAttachmentPreviewer extends StatefulWidget {
|
||||||
const HtmlAttachmentPreviewer({
|
const HtmlAttachmentPreviewer({
|
||||||
super.key,
|
super.key,
|
||||||
required this.htmlContent,
|
required this.htmlContent,
|
||||||
@@ -24,46 +26,61 @@ class HtmlAttachmentPreviewer extends StatelessWidget {
|
|||||||
final VoidCallback downloadAttachmentClicked;
|
final VoidCallback downloadAttachmentClicked;
|
||||||
final ResponsiveUtils responsiveUtils;
|
final ResponsiveUtils responsiveUtils;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<HtmlAttachmentPreviewer> createState() => _HtmlAttachmentPreviewerState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _HtmlAttachmentPreviewerState extends State<HtmlAttachmentPreviewer> {
|
||||||
|
final focusNode = FocusNode();
|
||||||
|
|
||||||
static const double _verticalMargin = 16;
|
static const double _verticalMargin = 16;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
focusNode.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Column(
|
final child = Column(
|
||||||
children: [
|
children: [
|
||||||
TopBarAttachmentViewer(
|
TopBarAttachmentViewer(
|
||||||
title: title,
|
title: widget.title,
|
||||||
closeAction: popBack,
|
closeAction: popBack,
|
||||||
downloadAction: downloadAttachmentClicked,
|
downloadAction: widget.downloadAttachmentClicked,
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: LayoutBuilder(
|
child: LayoutBuilder(
|
||||||
builder: (context, constraints) {
|
builder: (context, constraints) {
|
||||||
return SingleChildScrollView(
|
return Center(
|
||||||
child: GestureDetector(
|
child: SingleChildScrollView(
|
||||||
onTap: popBack,
|
child: GestureDetector(
|
||||||
child: PointerInterceptor(
|
onTap: popBack,
|
||||||
child: ColoredBox(
|
child: PointerInterceptor(
|
||||||
color: Colors.transparent,
|
child: ColoredBox(
|
||||||
child: Center(
|
color: Colors.transparent,
|
||||||
child: Container(
|
child: Center(
|
||||||
margin: const EdgeInsets.symmetric(vertical: _verticalMargin),
|
child: Container(
|
||||||
color: Colors.white,
|
margin: const EdgeInsets.symmetric(vertical: _verticalMargin),
|
||||||
child: ResponsiveWidget(
|
color: Colors.white,
|
||||||
responsiveUtils: responsiveUtils,
|
child: ResponsiveWidget(
|
||||||
desktop: _buildHtmlViewerWith(
|
responsiveUtils: widget.responsiveUtils,
|
||||||
context,
|
desktop: _buildHtmlViewerWith(
|
||||||
width: constraints.maxWidth * 0.8,
|
context,
|
||||||
height: constraints.maxHeight - _verticalMargin * 2
|
width: constraints.maxWidth * 0.8,
|
||||||
),
|
height: constraints.maxHeight - _verticalMargin * 2
|
||||||
tablet: _buildHtmlViewerWith(
|
),
|
||||||
context,
|
tablet: _buildHtmlViewerWith(
|
||||||
width: constraints.maxWidth * 0.8,
|
context,
|
||||||
height: constraints.maxHeight - _verticalMargin * 2
|
width: constraints.maxWidth * 0.8,
|
||||||
),
|
height: constraints.maxHeight - _verticalMargin * 2
|
||||||
mobile: _buildHtmlViewerWith(
|
),
|
||||||
context,
|
mobile: _buildHtmlViewerWith(
|
||||||
width: constraints.maxWidth,
|
context,
|
||||||
height: constraints.maxHeight - _verticalMargin * 2
|
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, {
|
BuildContext context, {
|
||||||
required double width,
|
required double width,
|
||||||
required double height,
|
required double height,
|
||||||
}) {
|
}) {
|
||||||
return HtmlContentViewerOnWeb(
|
return PlatformInfo.isWeb
|
||||||
contentHtml: htmlContent,
|
? HtmlContentViewerOnWeb(
|
||||||
widthContent: width,
|
contentHtml: widget.htmlContent,
|
||||||
heightContent: height,
|
widthContent: width,
|
||||||
direction: AppUtils.getCurrentDirection(context),
|
heightContent: height,
|
||||||
mailtoDelegate: (uri) {
|
direction: AppUtils.getCurrentDirection(context),
|
||||||
popBack();
|
mailtoDelegate: (uri) {
|
||||||
mailToClicked(uri);
|
popBack();
|
||||||
},
|
widget.mailToClicked(uri);
|
||||||
keepWidthWhileLoading: true,
|
},
|
||||||
);
|
keepWidthWhileLoading: true,
|
||||||
|
)
|
||||||
|
: HtmlContentViewer(
|
||||||
|
contentHtml: widget.htmlContent,
|
||||||
|
initialWidth: width,
|
||||||
|
direction: AppUtils.getCurrentDirection(context),
|
||||||
|
onMailtoDelegateAction: (uri) async {
|
||||||
|
widget.mailToClicked(uri);
|
||||||
|
},
|
||||||
|
keepWidthWhileLoading: true,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user