Fix display content full screen in Email Detailed

This commit is contained in:
dab246
2022-04-14 14:13:08 +07:00
committed by Dat H. Pham
parent 2bae5c31ce
commit 8a527a1ead
8 changed files with 98 additions and 148 deletions
@@ -108,6 +108,7 @@ extension AppColor on Color {
static const colorFocusButton = Color(0x14818C99); static const colorFocusButton = Color(0x14818C99);
static const colorBorderEmailAddressInvalid = Color(0xFFFF3347); static const colorBorderEmailAddressInvalid = Color(0xFFFF3347);
static const colorBgMailboxSelected = Color(0xFF99E4E8EC); static const colorBgMailboxSelected = Color(0xFF99E4E8EC);
static const colorLoading = Color(0x2999A2AD);
static const mapGradientColor = [ static const mapGradientColor = [
[Color(0xFF21D4FD), Color(0xFFB721FF)], [Color(0xFF21D4FD), Color(0xFFB721FF)],
@@ -3,6 +3,8 @@ import 'package:core/data/network/dio_client.dart';
import 'package:core/presentation/utils/html_transformer/base/dom_transformer.dart'; import 'package:core/presentation/utils/html_transformer/base/dom_transformer.dart';
import 'package:html/dom.dart'; import 'package:html/dom.dart';
import '../html_template.dart';
class AddTooltipLinkTransformer extends DomTransformer { class AddTooltipLinkTransformer extends DomTransformer {
const AddTooltipLinkTransformer(); const AddTooltipLinkTransformer();
@@ -29,7 +31,7 @@ class AddTooltipLinkTransformer extends DomTransformer {
if (children.isEmpty && text.isNotEmpty && url != null) { if (children.isEmpty && text.isNotEmpty && url != null) {
final innerHtml = element.innerHtml; final innerHtml = element.innerHtml;
final tagClass = element.attributes['class']; final tagClass = element.attributes['class'];
element.attributes['class'] = '$tagClass tooltip'; element.attributes['class'] = '$tagClass $nameClassToolTip';
element.innerHtml = innerHtml + textHasToolTip(url); element.innerHtml = innerHtml + textHasToolTip(url);
} }
} }
@@ -1,6 +1,8 @@
final nameClassToolTip = 'tmail-tooltip';
final tooltipLinkCss = ''' final tooltipLinkCss = '''
.tooltip .tooltiptext { .$nameClassToolTip .tooltiptext {
visibility: hidden; visibility: hidden;
max-width: 400px; max-width: 400px;
background-color: black; background-color: black;
@@ -14,7 +16,7 @@ final tooltipLinkCss = '''
position: absolute; position: absolute;
z-index: 1; z-index: 1;
} }
.tooltip:hover .tooltiptext { .$nameClassToolTip:hover .tooltiptext {
visibility: visible; visibility: visible;
} }
'''; ''';
@@ -6,7 +6,7 @@ import 'package:core/presentation/extensions/color_extension.dart';
import 'package:core/presentation/utils/html_transformer/html_template.dart'; import 'package:core/presentation/utils/html_transformer/html_template.dart';
import 'package:core/presentation/views/html_viewer/html_viewer_controller_for_web.dart'; import 'package:core/presentation/views/html_viewer/html_viewer_controller_for_web.dart';
import 'package:core/utils/app_logger.dart'; import 'package:core/utils/app_logger.dart';
import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart';
import 'package:universal_html/html.dart' as html; import 'package:universal_html/html.dart' as html;
import 'package:core/presentation/utils/shims/dart_ui.dart' as ui; import 'package:core/presentation/utils/shims/dart_ui.dart' as ui;
@@ -227,7 +227,7 @@ class _HtmlContentViewerOnWebState extends State<HtmlContentViewerOnWeb> {
width: actualWidth, width: actualWidth,
child: _buildWebView(), child: _buildWebView(),
), ),
if (_isLoading) Align(alignment: Alignment.center, child: _buildLoadingView()) if (_isLoading) Align(alignment: Alignment.topCenter, child: _buildLoadingView())
], ],
); );
} }
@@ -238,7 +238,7 @@ class _HtmlContentViewerOnWebState extends State<HtmlContentViewerOnWeb> {
child: SizedBox( child: SizedBox(
width: 30, width: 30,
height: 30, height: 30,
child: CircularProgressIndicator(color: AppColor.colorTextButton))); child: CupertinoActivityIndicator(color: AppColor.colorLoading)));
} }
Widget _buildWebView() { Widget _buildWebView() {
@@ -1,6 +1,7 @@
import 'dart:async'; import 'dart:async';
import 'package:core/core.dart'; import 'package:core/core.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@@ -11,8 +12,7 @@ import 'dart:developer' as developer;
class HtmlContentViewer extends StatefulWidget { class HtmlContentViewer extends StatefulWidget {
final String contentHtml; final String contentHtml;
final double widthContent; final double heightContent;
final Widget? loadingWidget;
/// Register this callback if you want a reference to the [WebViewController]. /// Register this callback if you want a reference to the [WebViewController].
final void Function(WebViewController controller)? onCreated; final void Function(WebViewController controller)? onCreated;
@@ -28,8 +28,7 @@ class HtmlContentViewer extends StatefulWidget {
const HtmlContentViewer({ const HtmlContentViewer({
Key? key, Key? key,
required this.contentHtml, required this.contentHtml,
required this.widthContent, required this.heightContent,
this.loadingWidget,
this.onCreated, this.onCreated,
this.urlLauncherDelegate, this.urlLauncherDelegate,
this.mailtoDelegate, this.mailtoDelegate,
@@ -41,8 +40,7 @@ class HtmlContentViewer extends StatefulWidget {
class _HtmlContentViewState extends State<HtmlContentViewer> { class _HtmlContentViewState extends State<HtmlContentViewer> {
double? _webViewHeight = 1.0; late double actualHeight;
double? _webViewWidth = 1.0;
double minHeight = 100; double minHeight = 100;
double minWidth = 300; double minWidth = 300;
String? _htmlData; String? _htmlData;
@@ -52,7 +50,7 @@ class _HtmlContentViewState extends State<HtmlContentViewer> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_webViewWidth = widget.widthContent; actualHeight = widget.heightContent;
_htmlData = _generateHtmlDocument(widget.contentHtml); _htmlData = _generateHtmlDocument(widget.contentHtml);
} }
@@ -63,29 +61,27 @@ class _HtmlContentViewState extends State<HtmlContentViewer> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Stack( return LayoutBuilder(builder: (context, constraints) {
children: [ log('_HtmlContentViewState::build(): maxWidth: ${constraints.maxWidth}');
SizedBox( return Stack(
height: _webViewHeight, children: [
width: _webViewWidth, SizedBox(
child: _buildWebView(), height: actualHeight,
), width: constraints.maxWidth,
if (_isLoading) Align(alignment: Alignment.center, child: _buildLoadingView()) child: _buildWebView()),
], if (_isLoading) Align(alignment: Alignment.center, child: _buildLoadingView())
); ],
);
});
} }
Widget _buildLoadingView() { Widget _buildLoadingView() {
if (widget.loadingWidget != null) { return Padding(
return widget.loadingWidget!;
} else {
return Padding(
padding: EdgeInsets.all(16), padding: EdgeInsets.all(16),
child: SizedBox( child: SizedBox(
width: 30, width: 30,
height: 30, height: 30,
child: CircularProgressIndicator(color: AppColor.primaryColor))); child: CupertinoActivityIndicator(color: AppColor.colorLoading)));
}
} }
Widget _buildWebView() { Widget _buildWebView() {
@@ -110,7 +106,7 @@ class _HtmlContentViewState extends State<HtmlContentViewer> {
final scrollHeightWithBuffer = scrollHeight + 30.0; final scrollHeightWithBuffer = scrollHeight + 30.0;
if (scrollHeightWithBuffer > minHeight) { if (scrollHeightWithBuffer > minHeight) {
setState(() { setState(() {
_webViewHeight = scrollHeightWithBuffer; actualHeight = scrollHeightWithBuffer;
_isLoading = false; _isLoading = false;
}); });
} }
+16 -16
View File
@@ -13,10 +13,8 @@ import 'package:tmail_ui_user/features/composer/presentation/extensions/prefix_e
import 'package:tmail_ui_user/features/email/presentation/email_controller.dart'; import 'package:tmail_ui_user/features/email/presentation/email_controller.dart';
import 'package:tmail_ui_user/features/email/presentation/widgets/app_bar_mail_widget_builder.dart'; import 'package:tmail_ui_user/features/email/presentation/widgets/app_bar_mail_widget_builder.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_file_tile_builder.dart';
import 'package:tmail_ui_user/features/email/presentation/widgets/attachments_place_holder_loading_widget.dart';
import 'package:tmail_ui_user/features/email/presentation/widgets/bottom_bar_mail_widget_builder.dart'; import 'package:tmail_ui_user/features/email/presentation/widgets/bottom_bar_mail_widget_builder.dart';
import 'package:tmail_ui_user/features/email/presentation/widgets/email_action_cupertino_action_sheet_action_builder.dart'; import 'package:tmail_ui_user/features/email/presentation/widgets/email_action_cupertino_action_sheet_action_builder.dart';
import 'package:tmail_ui_user/features/email/presentation/widgets/email_content_place_holder_loading_widget.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/user_setting_popup_menu_mixin.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/user_setting_popup_menu_mixin.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart'; import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
import 'package:filesize/filesize.dart'; import 'package:filesize/filesize.dart';
@@ -197,8 +195,8 @@ class EmailView extends GetView with UserSettingPopupMenuMixin, NetworkConnectio
padding: EdgeInsets.only(right: 16), padding: EdgeInsets.only(right: 16),
child: SelectableText( child: SelectableText(
'${emailController.mailboxDashBoardController.selectedEmail.value?.getEmailTitle()}', '${emailController.mailboxDashBoardController.selectedEmail.value?.getEmailTitle()}',
maxLines: 3, maxLines: kIsWeb ? 3 : null,
minLines: 1, minLines: kIsWeb ? 1 : null,
cursorColor: AppColor.colorTextButton, cursorColor: AppColor.colorTextButton,
style: TextStyle( style: TextStyle(
fontSize: 20, fontSize: 20,
@@ -237,6 +235,7 @@ class EmailView extends GetView with UserSettingPopupMenuMixin, NetworkConnectio
Expanded(child: _buildEmailContent(context, constraints)) Expanded(child: _buildEmailContent(context, constraints))
else else
_buildEmailContent(context, constraints), _buildEmailContent(context, constraints),
SizedBox(height: 16),
], ],
); );
}) })
@@ -398,7 +397,7 @@ class EmailView extends GetView with UserSettingPopupMenuMixin, NetworkConnectio
(failure) => SizedBox.shrink(), (failure) => SizedBox.shrink(),
(success) { (success) {
if (success is LoadingState) { if (success is LoadingState) {
return AttachmentsPlaceHolderLoading(responsiveUtils: responsiveUtils); return SizedBox.shrink();
} else { } else {
final attachments = emailController.attachments.listAttachmentsDisplayedOutSide; final attachments = emailController.attachments.listAttachmentsDisplayedOutSide;
return attachments.isNotEmpty return attachments.isNotEmpty
@@ -412,9 +411,9 @@ class EmailView extends GetView with UserSettingPopupMenuMixin, NetworkConnectio
if (responsiveUtils.isMobileDevice(context)) { if (responsiveUtils.isMobileDevice(context)) {
return 2; return 2;
} else if (responsiveUtils.isTablet(context)) { } else if (responsiveUtils.isTablet(context)) {
return 4;
} else {
return 3; return 3;
} else {
return 4;
} }
} }
@@ -439,7 +438,7 @@ class EmailView extends GetView with UserSettingPopupMenuMixin, NetworkConnectio
key: Key('list_attachment'), key: Key('list_attachment'),
primary: false, primary: false,
shrinkWrap: true, shrinkWrap: true,
padding: EdgeInsets.only(top: isExpand ? 0 : 16), padding: EdgeInsets.only(top: isExpand ? 0 : 16, bottom: 16),
itemCount: countAttachments, itemCount: countAttachments,
gridDelegate: SliverGridDelegateFixedHeight( gridDelegate: SliverGridDelegateFixedHeight(
height: 60, height: 60,
@@ -523,26 +522,27 @@ class EmailView extends GetView with UserSettingPopupMenuMixin, NetworkConnectio
(failure) => SizedBox.shrink(), (failure) => SizedBox.shrink(),
(success) { (success) {
if (success is LoadingState) { if (success is LoadingState) {
return EmailContentPlaceHolderLoading(responsiveUtils: responsiveUtils); return Padding(
padding: EdgeInsets.all(16),
child: SizedBox(
width: 30,
height: 30,
child: CupertinoActivityIndicator(color: AppColor.colorLoading)));
} else { } else {
if (emailController.emailContents.isNotEmpty) { if (emailController.emailContents.isNotEmpty) {
final allEmailContents = emailController.emailContents final allEmailContents = emailController.emailContents.asHtmlString;
.map((emailContent) => emailContent.asHtml)
.toList()
.join('<br>');
if (kIsWeb) { if (kIsWeb) {
return HtmlContentViewerOnWeb( return HtmlContentViewerOnWeb(
widthContent: constraints.maxWidth, widthContent: constraints.maxWidth,
heightContent: MediaQuery.of(context).size.height, heightContent: responsiveUtils.getSizeScreenHeight(context),
contentHtml: allEmailContents, contentHtml: allEmailContents,
controller: HtmlViewerControllerForWeb(), controller: HtmlViewerControllerForWeb(),
mailtoDelegate: (uri) => emailController.openMailToLink(uri)); mailtoDelegate: (uri) => emailController.openMailToLink(uri));
} else { } else {
return HtmlContentViewer( return HtmlContentViewer(
widthContent: MediaQuery.of(context).size.width, heightContent: responsiveUtils.getSizeScreenHeight(context),
contentHtml: allEmailContents, contentHtml: allEmailContents,
loadingWidget: EmailContentPlaceHolderLoading(responsiveUtils: responsiveUtils),
mailtoDelegate: (uri) async => emailController.openMailToLink(uri)); mailtoDelegate: (uri) async => emailController.openMailToLink(uri));
} }
} else { } else {
@@ -1,60 +0,0 @@
import 'package:core/core.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:model/model.dart';
class EmailContentItemBuilder {
final BuildContext _context;
final EmailContent _emailContent;
final Widget? loadingWidget;
final BoxConstraints _constraints;
EmailContentItemBuilder(
this._context,
this._emailContent,
this._constraints,
{
this.loadingWidget
}
);
Widget build() {
return Theme(
data: ThemeData(
splashColor: Colors.transparent,
highlightColor: Colors.transparent),
child: MediaQuery(
data: MediaQueryData(padding: EdgeInsets.zero),
child: _buildItem()
)
);
}
Widget _buildItem() {
switch(_emailContent.type) {
case EmailContentType.textHtml:
if (kIsWeb) {
return HtmlContentViewerOnWeb(
widthContent: _constraints.maxWidth,
heightContent: MediaQuery.of(_context).size.height,
contentHtml: _emailContent.content,
controller: HtmlViewerControllerForWeb());
} else {
return HtmlContentViewer(
widthContent: MediaQuery.of(_context).size.width,
contentHtml: _emailContent.content,
loadingWidget: loadingWidget);
}
case EmailContentType.textPlain:
return Padding(
padding: EdgeInsets.only(top: 20),
child: SelectableText(
_emailContent.content,
style: TextStyle(fontSize: 14, color: AppColor.colorNameEmail, fontWeight: FontWeight.normal)));
case EmailContentType.other:
return SizedBox.shrink();
}
}
}
@@ -253,44 +253,51 @@ class EmailTileBuilder {
paddingIconSelect: EdgeInsets.all(5)), paddingIconSelect: EdgeInsets.all(5)),
), ),
if (_selectModeAll == SelectMode.INACTIVE) SizedBox(width: 10), if (_selectModeAll == SelectMode.INACTIVE) SizedBox(width: 10),
Container(width: 180, child: _isSearchEnabled Container(
? RichTextBuilder( width: 160,
_getInformationSender(), child: _isSearchEnabled
'${_searchQuery!.value}', ? RichTextBuilder(
TextStyle(fontSize: 15, color: AppColor.colorNameEmail, fontWeight: FontWeight.w600), _getInformationSender(),
TextStyle(fontSize: 15, color: AppColor.colorNameEmail, backgroundColor: AppColor.bgWordSearch, fontWeight: FontWeight.w600)).build() '${_searchQuery!.value}',
: Text('${_getInformationSender()}', TextStyle(fontSize: 15, color: AppColor.colorNameEmail, fontWeight: FontWeight.w600),
maxLines: 1, TextStyle(fontSize: 15, color: AppColor.colorNameEmail, backgroundColor: AppColor.bgWordSearch, fontWeight: FontWeight.w600)).build()
style: TextStyle(fontSize: 15, color: AppColor.colorNameEmail, fontWeight: FontWeight.w600)), : Text('${_getInformationSender()}',
maxLines: 1,
overflow: kIsWeb ? null : TextOverflow.ellipsis,
style: TextStyle(fontSize: 15, color: AppColor.colorNameEmail, fontWeight: FontWeight.w600)),
), ),
SizedBox(width: 10), SizedBox(width: 24),
Expanded(child: _buildSubjectAndContent()), Expanded(child: _buildSubjectAndContent()),
SizedBox(width: 10), SizedBox(width: 16),
if (_searchStatus == SearchStatus.ACTIVE && _presentationEmail.mailboxName.isNotEmpty) if (_searchStatus == SearchStatus.ACTIVE && _presentationEmail.mailboxName.isNotEmpty)
Container( Container(
margin: EdgeInsets.only(left: 8), margin: EdgeInsets.only(left: 8),
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 3), padding: EdgeInsets.symmetric(horizontal: 8, vertical: 3),
constraints: BoxConstraints(maxWidth: 100), constraints: BoxConstraints(maxWidth: 80),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(10), color: AppColor.backgroundCounterMailboxColor), decoration: BoxDecoration(borderRadius: BorderRadius.circular(10), color: AppColor.backgroundCounterMailboxColor),
child: Text('${_presentationEmail.mailboxName}', child: Text('${_presentationEmail.mailboxName}',
maxLines: 1, maxLines: 1,
overflow: kIsWeb ? null : TextOverflow.ellipsis,
style: TextStyle(fontSize: 10, color: AppColor.mailboxTextColor, fontWeight: FontWeight.bold), style: TextStyle(fontSize: 10, color: AppColor.mailboxTextColor, fontWeight: FontWeight.bold),
) )
), ),
if (_presentationEmail.hasAttachment == true) if (_presentationEmail.hasAttachment == true)
Padding(padding: EdgeInsets.only(left: 8), Padding(padding: EdgeInsets.only(left: 8),
child: (ButtonBuilder(_imagePaths.icAttachment) child: (ButtonBuilder(_imagePaths.icAttachment)
..paddingIcon(EdgeInsets.zero) ..paddingIcon(EdgeInsets.zero)
..size(16)) ..size(16))
.build()), .build()),
Padding(padding: EdgeInsets.only(right: 20, left: 8), Padding(
child: Text('${_presentationEmail.getReceivedAt(Localizations.localeOf(_context).toLanguageTag())}', padding: EdgeInsets.only(right: 20, left: 8),
maxLines: 1, child: Text('${_presentationEmail.getReceivedAt(Localizations.localeOf(_context).toLanguageTag())}',
style: TextStyle(fontSize: 13, color: AppColor.colorContentEmail, fontWeight: FontWeight.normal))), maxLines: 1,
textAlign: TextAlign.right,
overflow: kIsWeb ? null : TextOverflow.ellipsis,
style: TextStyle(fontSize: 13, color: AppColor.colorContentEmail, fontWeight: FontWeight.normal))),
]), ]),
if (_selectModeAll == SelectMode.INACTIVE) if (_selectModeAll == SelectMode.INACTIVE)
Padding( Padding(
padding: EdgeInsets.only(top: 10, bottom: 10, left: 70), padding: EdgeInsets.only(top: 7.5, bottom: 7.5, left: 70),
child: Divider(color: AppColor.lineItemListColor, height: 1, thickness: 0.2)), child: Divider(color: AppColor.lineItemListColor, height: 1, thickness: 0.2)),
]), ]),
); );
@@ -299,24 +306,24 @@ class EmailTileBuilder {
Widget _buildSubjectAndContent() { Widget _buildSubjectAndContent() {
return LayoutBuilder(builder: (context, constraints) { return LayoutBuilder(builder: (context, constraints) {
log('EmailTileBuilder::_buildSubjectAndContent(): maxWidth(Subject+Content): ${constraints.maxWidth}'); log('EmailTileBuilder::_buildSubjectAndContent(): maxWidth(Subject+Content): ${constraints.maxWidth}');
return Row( return Row(children: [
children: [ Container(
Flexible( constraints: BoxConstraints(maxWidth: constraints.maxWidth / 2),
child: Container( child: _isSearchEnabled
constraints: BoxConstraints(maxWidth: constraints.maxWidth / 2), ? RichTextBuilder(
child: _isSearchEnabled '${_presentationEmail.getEmailTitle()}',
? RichTextBuilder( '${_searchQuery!.value}',
'${_presentationEmail.getEmailTitle()}', TextStyle(fontSize: 13, color: AppColor.colorNameEmail, fontWeight: FontWeight.w600),
'${_searchQuery!.value}', TextStyle(fontSize: 13, backgroundColor: AppColor.bgWordSearch, color: AppColor.colorNameEmail)).build()
TextStyle(fontSize: 13, color: AppColor.colorNameEmail, fontWeight: FontWeight.w600), : Text('${_presentationEmail.getEmailTitle()}',
TextStyle(fontSize: 13, backgroundColor: AppColor.bgWordSearch, color: AppColor.colorNameEmail)).build() maxLines: 1,
: Text('${_presentationEmail.getEmailTitle()}', overflow: kIsWeb ? null : TextOverflow.ellipsis,
maxLines: 1, style: TextStyle(fontSize: 13, color: AppColor.colorNameEmail, fontWeight: FontWeight.w600))
style: TextStyle(fontSize: 13, color: AppColor.colorNameEmail, fontWeight: FontWeight.w600)) ),
) if (_presentationEmail.getEmailTitle().isNotEmpty) SizedBox(width: 12),
), Expanded(
if (_presentationEmail.getEmailTitle().isNotEmpty) SizedBox(width: 12), child: Container(
Expanded(child: _isSearchEnabled child: _isSearchEnabled
? RichTextBuilder( ? RichTextBuilder(
'${_presentationEmail.getPartialContent()}', '${_presentationEmail.getPartialContent()}',
'${_searchQuery!.value}', '${_searchQuery!.value}',
@@ -324,9 +331,11 @@ class EmailTileBuilder {
TextStyle(fontSize: 13, color: AppColor.colorContentEmail, backgroundColor: AppColor.bgWordSearch)).build() TextStyle(fontSize: 13, color: AppColor.colorContentEmail, backgroundColor: AppColor.bgWordSearch)).build()
: Text('${_presentationEmail.getPartialContent()}', : Text('${_presentationEmail.getPartialContent()}',
maxLines: 1, maxLines: 1,
style: TextStyle(fontSize: 13, color: AppColor.colorContentEmail, fontWeight: FontWeight.normal))), overflow: kIsWeb ? null : TextOverflow.ellipsis,
] style: TextStyle(fontSize: 13, color: AppColor.colorContentEmail, fontWeight: FontWeight.normal))
); )
),
]);
}); });
} }