From 49c64dea7287d1d735cd1789e414911df0ff8f97 Mon Sep 17 00:00:00 2001 From: dab246 Date: Fri, 18 Mar 2022 15:55:15 +0700 Subject: [PATCH] Fix editor and attachment in composer on web --- .../presentation/composer_controller.dart | 18 ++-- .../presentation/composer_view_web.dart | 97 ++++++++----------- pubspec.yaml | 2 +- 3 files changed, 51 insertions(+), 66 deletions(-) diff --git a/lib/features/composer/presentation/composer_controller.dart b/lib/features/composer/presentation/composer_controller.dart index 6f3626a1b..8678c0257 100644 --- a/lib/features/composer/presentation/composer_controller.dart +++ b/lib/features/composer/presentation/composer_controller.dart @@ -232,6 +232,12 @@ class ComposerController extends BaseController { } } + void setFullScreenEditor() { + Future.delayed(const Duration(milliseconds: 1000), () { + htmlControllerBrowser.setFullScreen(); + }); + } + Tuple2? _getHeaderEmailQuoted(String locale, ComposerArguments arguments) { if (arguments.presentationEmail != null) { final sentDate = arguments.presentationEmail?.sentAt; @@ -263,12 +269,6 @@ class ComposerController extends BaseController { listBccEmailAddress = recipients.value3.toSet().filterEmailAddress(userEmailAddress); } - if (listCcEmailAddress.isNotEmpty || listBccEmailAddress.isNotEmpty) { - expandMode.value = ExpandMode.EXPAND; - } else { - expandMode.value = ExpandMode.COLLAPSE; - } - if (listToEmailAddress.isNotEmpty || listCcEmailAddress.isNotEmpty || listBccEmailAddress.isNotEmpty) { isInitialRecipient.value = true; } @@ -319,7 +319,7 @@ class ComposerController extends BaseController { .toList() .join('
') ?? ''; - final emailQuotedHtml = '


$headerEmailQuotedAsHtml${trustAsHtml.addBlockQuoteTag()}
'; + final emailQuotedHtml = '

$headerEmailQuotedAsHtml${trustAsHtml.addBlockQuoteTag()}
'; return emailQuotedHtml; } @@ -369,7 +369,6 @@ class ComposerController extends BaseController { } else { userAgent = FkUserAgent.userAgent ?? ''; } - log('ComposerController - userAgentPlatform(): userAgent: $userAgent'); } on Exception { userAgent = ''; } @@ -666,8 +665,7 @@ class ComposerController extends BaseController { void _updateTextForEditor() async { final textCurrent = await htmlControllerBrowser.getText(); - log('_updateTextForEditor() | textCurrent: $textCurrent'); - htmlControllerBrowser.insertHtml(textCurrent); + htmlControllerBrowser.insertText(textCurrent); } void deleteComposer() { diff --git a/lib/features/composer/presentation/composer_view_web.dart b/lib/features/composer/presentation/composer_view_web.dart index 2f9d23691..771a4e805 100644 --- a/lib/features/composer/presentation/composer_view_web.dart +++ b/lib/features/composer/presentation/composer_view_web.dart @@ -55,8 +55,8 @@ class ComposerView extends GetWidget { color: Colors.transparent, child: Container( decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(20))), - width: responsiveUtils.getSizeWidthScreen(context) * 0.5, - height: responsiveUtils.getSizeHeightScreen(context) * 0.65, + width: responsiveUtils.getSizeWidthScreen(context) * 0.55, + height: responsiveUtils.getSizeHeightScreen(context) * 0.75, child: PointerInterceptor(child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -119,8 +119,8 @@ class ComposerView extends GetWidget { shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(20))), child: Container( decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(20))), - width: responsiveUtils.getSizeWidthScreen(context) * 0.8, - height: responsiveUtils.getSizeHeightScreen(context) * 0.85, + width: responsiveUtils.getSizeWidthScreen(context) * 0.85, + height: responsiveUtils.getSizeHeightScreen(context) * 0.9, child: ClipRRect( borderRadius: BorderRadius.all(Radius.circular(20)), child: PointerInterceptor(child: Column( @@ -391,52 +391,55 @@ class ComposerView extends GetWidget { } Widget _buildEditorAndAttachments(BuildContext context) { - return SingleChildScrollView( - physics: ClampingScrollPhysics(), - child: Column( - children: [ - Obx(() => controller.attachments.isNotEmpty - ? Padding( - padding: EdgeInsets.symmetric(vertical: 4, horizontal: 10), - child: _buildAttachmentsTitle(context, controller.attachments, controller.expandModeAttachments.value)) - : SizedBox.shrink()), - Obx(() => controller.attachments.isEmpty - ? _buildAttachmentsLoadingView() - : SizedBox.shrink()), - Obx(() => controller.attachments.isNotEmpty - ? Padding( - padding: EdgeInsets.only(bottom: 8, left: 10, right: 10), - child: _buildAttachmentsList(context, controller.attachments, controller.expandModeAttachments.value)) - : SizedBox.shrink()), - Padding( - padding: EdgeInsets.symmetric(horizontal: 10), - child: _buildComposerEditor(context)), - ] - ) + return Column( + children: [ + Obx(() => controller.attachments.isNotEmpty + ? Padding( + padding: EdgeInsets.symmetric(vertical: 4, horizontal: 10), + child: _buildAttachmentsTitle(context, controller.attachments, controller.expandModeAttachments.value)) + : SizedBox.shrink()), + Obx(() => controller.attachments.isEmpty + ? _buildAttachmentsLoadingView() + : SizedBox.shrink()), + Obx(() => controller.attachments.isNotEmpty && controller.expandModeAttachments.value == ExpandMode.COLLAPSE + ? Padding(padding: EdgeInsets.symmetric(horizontal: 10), child: Divider(color: AppColor.colorDividerComposer, height: 1)) + : SizedBox.shrink()), + Obx(() => controller.attachments.isNotEmpty + ? Padding( + padding: EdgeInsets.only(bottom: 8, left: 10, right: 10), + child: _buildAttachmentsList(context, controller.attachments, controller.expandModeAttachments.value)) + : SizedBox.shrink()), + Expanded(child: Padding(padding: EdgeInsets.symmetric(horizontal: 10), child: _buildEditor(context))), + ] ); } - Widget _buildComposerEditor(BuildContext context) { - return Obx(() => HtmlEditorBrowser.HtmlEditor( + Widget _buildEditor(BuildContext context) { + return HtmlEditorBrowser.HtmlEditor( key: Key('composer_editor_web'), controller: controller.htmlControllerBrowser, htmlEditorOptions: HtmlEditorBrowser.HtmlEditorOptions( - hint: '', + hint: '

', initialText: controller.initTextEditorComposer, - autoAdjustHeight: true, darkMode: false, - disableScrollbarEditor: true, ), htmlToolbarOptions: HtmlEditorBrowser.HtmlToolbarOptions( toolbarPosition: HtmlEditorBrowser.ToolbarPosition.custom ), otherOptions: HtmlEditorBrowser.OtherOptions(height: 550), - callbacks: HtmlEditorBrowser.Callbacks(onBeforeCommand: (String? currentHtml) { - controller.setTextEditor(currentHtml); - }, onChangeContent: (String? changed) { - controller.setTextEditor(changed); - }), - )); + callbacks: HtmlEditorBrowser.Callbacks( + onBeforeCommand: (String? currentHtml) { + log('ComposerView::_buildComposerEditor(): onBeforeCommand'); + controller.setTextEditor(currentHtml); + }, onChangeContent: (String? changed) { + log('ComposerView::_buildComposerEditor(): onChangeContent'); + controller.setTextEditor(changed); + }, onInit: () { + log('ComposerView::_buildComposerEditor(): onInit'); + controller.setFullScreenEditor(); + } + ), + ); } Widget _buildAttachmentsLoadingView({EdgeInsets? padding, double? size}) { @@ -477,24 +480,8 @@ class ComposerView extends GetWidget { } Widget _buildAttachmentsList(BuildContext context, List attachments, ExpandMode expandMode) { - if (expandMode == ExpandMode.EXPAND) { - return LayoutBuilder(builder: (context, constraints) { - return GridView.builder( - key: Key('list_attachment_full'), - primary: false, - shrinkWrap: true, - itemCount: attachments.length, - gridDelegate: SliverGridDelegateFixedHeight( - height: 60, - crossAxisCount: _getMaxItemRowListAttachment(context, constraints), - crossAxisSpacing: 8.0, - mainAxisSpacing: 8.0), - itemBuilder: (context, index) => - (AttachmentFileComposerBuilder(context, imagePaths, attachments[index]) - ..addOnDeleteAttachmentAction((attachment) => controller.removeAttachmentAction(attachment))) - .build() - ); - }); + if (expandMode == ExpandMode.COLLAPSE) { + return SizedBox.shrink(); } else { return LayoutBuilder(builder: (context, constraints) { return Align( diff --git a/pubspec.yaml b/pubspec.yaml index 5552d31e7..a5cf9d12d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -128,7 +128,7 @@ dependencies: html_editor_enhanced: git: url: https://github.com/dab246/html-editor-enhanced.git - ref: html_editor_for_web + ref: improvements # fk_user_agent fk_user_agent: 2.1.0