diff --git a/core/lib/presentation/views/text/text_field_builder.dart b/core/lib/presentation/views/text/text_field_builder.dart index bcf87b2dc..fe22e3a50 100644 --- a/core/lib/presentation/views/text/text_field_builder.dart +++ b/core/lib/presentation/views/text/text_field_builder.dart @@ -11,44 +11,40 @@ class TextFieldBuilder { int? _maxLines = 1; TextEditingController? _textController; - TextFieldBuilder key(Key key) { + void key(Key key) { _key = key; - return this; } - TextFieldBuilder onChange(ValueChanged onChange) { + void onChange(ValueChanged onChange) { _onTextChange = onChange; - return this; } - TextFieldBuilder textStyle(TextStyle style) { + void textStyle(TextStyle style) { _textStyle = style; - return this; } - TextFieldBuilder textInputAction(TextInputAction inputAction) { + void textInputAction(TextInputAction inputAction) { _textInputAction = inputAction; - return this; } - TextFieldBuilder textDecoration(InputDecoration inputDecoration) { + void textDecoration(InputDecoration inputDecoration) { _inputDecoration = inputDecoration; - return this; } - TextFieldBuilder obscureText(bool obscureText) { + void obscureText(bool obscureText) { _obscureText = obscureText; - return this; } - TextFieldBuilder setText(String value) { + void setText(String value) { _textController = TextEditingController.fromValue(TextEditingValue(text: value)); - return this; } - TextFieldBuilder maxLines(int? value) { + void addController(TextEditingController textEditingController) { + _textController = textEditingController; + } + + void maxLines(int? value) { _maxLines = value; - return this; } TextField build() { diff --git a/lib/features/composer/presentation/composer_bindings.dart b/lib/features/composer/presentation/composer_bindings.dart index 6484c797b..b00c91ecc 100644 --- a/lib/features/composer/presentation/composer_bindings.dart +++ b/lib/features/composer/presentation/composer_bindings.dart @@ -1,5 +1,6 @@ import 'package:core/core.dart'; import 'package:core/presentation/utils/app_toast.dart'; +import 'package:flutter/cupertino.dart'; import 'package:get/get.dart'; import 'package:html_editor_enhanced/html_editor.dart'; import 'package:tmail_ui_user/features/composer/data/datasource/autocomplete_datasource.dart'; @@ -45,12 +46,15 @@ class ComposerBindings extends Bindings { Get.lazyPut(() => SearchEmailAddressInteractor(Get.find())); Get.lazyPut(() => Uuid()); Get.lazyPut(() => HtmlEditorController()); + Get.lazyPut(() => TextEditingController()); Get.lazyPut(() => ComposerController( Get.find(), Get.find(), Get.find(), Get.find(), Get.find(), - Get.find())); + Get.find(), + Get.find(), + Get.find())); } } \ No newline at end of file diff --git a/lib/features/composer/presentation/composer_controller.dart b/lib/features/composer/presentation/composer_controller.dart index 9a3ccb6a2..1f0b49f18 100644 --- a/lib/features/composer/presentation/composer_controller.dart +++ b/lib/features/composer/presentation/composer_controller.dart @@ -42,7 +42,9 @@ class ComposerController extends BaseController { final SearchEmailAddressInteractor _searchEmailAddressInteractor; final AppToast _appToast; final Uuid _uuid; - final HtmlEditorController htmlEditorController; + final HtmlEditorController composerEditorController; + final TextEditingController subjectEmailInputController; + final HtmlMessagePurifier _htmlMessagePurifier; List listToEmailAddress = []; List listCcEmailAddress = []; @@ -57,7 +59,9 @@ class ComposerController extends BaseController { this._searchEmailAddressInteractor, this._appToast, this._uuid, - this.htmlEditorController, + this.composerEditorController, + this.subjectEmailInputController, + this._htmlMessagePurifier, ); @override @@ -92,19 +96,28 @@ class ComposerController extends BaseController { if (arguments is ComposerArguments) { composerArguments.value = arguments; _initToEmailAddress(); + _initSubjectEmail(); } } - EmailActionType getEmailActionType() => composerArguments.value != null - ? composerArguments.value!.emailActionType - : EmailActionType.compose; - - String getEmailSubject(BuildContext context) { - if (composerArguments.value != null && composerArguments.value?.presentationEmail != null) { - final subject = composerArguments.value!.presentationEmail?.subject; - return '${composerArguments.value!.emailActionType.prefixSubjectComposer(context)} $subject'; + void _initSubjectEmail() { + if (composerArguments.value != null + && composerArguments.value?.presentationEmail != null + && Get.context != null) { + final subject = '${composerArguments.value!.emailActionType.prefixSubjectComposer(Get.context!)} ' + '${composerArguments.value!.presentationEmail?.subject}'; + setSubjectEmail(subject); + subjectEmailInputController.text = subject; + } + } + + void initContentEmail() { + if (composerArguments.value != null + && composerArguments.value!.emailActionType != EmailActionType.compose + && Get.context != null) { + final contentEmailQuoted = _getBodyEmailQuotedAsHtml(Get.context!, _htmlMessagePurifier); + composerEditorController.setText(contentEmailQuoted); } - return ''; } Tuple2? getHeaderEmailQuoted(String locale) { @@ -176,14 +189,10 @@ class ComposerController extends BaseController { } } - String getBodyEmailQuotedAsHtml(BuildContext context, HtmlMessagePurifier htmlMessagePurifier) { + String _getBodyEmailQuotedAsHtml(BuildContext context, HtmlMessagePurifier htmlMessagePurifier) { final headerEmailQuoted = getHeaderEmailQuoted(Localizations.localeOf(context).toLanguageTag()); final contentEmail = getContentEmailQuoted(); - final placeHolderBodyEmailEditor = AppLocalizations.of(context).hint_content_email_composer - .addBlockTag('p', attribute: 'style=\"font-size:14px;color:#182952;\"') - .addNewLineTag(); - final headerEmailQuotedAsHtml = headerEmailQuoted != null ? AppLocalizations.of(context).header_email_quoted(headerEmailQuoted.value1, headerEmailQuoted.value2) .addBlockTag('p', attribute: 'style=\"font-size:14px;font-style:italic;color:#182952;\"') @@ -207,7 +216,7 @@ class ComposerController extends BaseController { .addNewLineTag(count: 2); } - final emailQuotedHtml = '$placeHolderBodyEmailEditor$headerEmailQuotedAsHtml$trustAsHtml' + final emailQuotedHtml = '$headerEmailQuotedAsHtml$trustAsHtml' .addBlockTag('div', attribute: 'style=\"padding-right:16px;padding-left:16px;background-color:#FBFBFF;width:100%\"'); return emailQuotedHtml; @@ -222,7 +231,7 @@ class ComposerController extends BaseController { final generatePartId = PartId(_uuid.v1()); final generateBlobId = Id(_uuid.v1()); - final emailBodyText = await htmlEditorController.getText(); + final emailBodyText = await composerEditorController.getText(); return Email( generateEmailId, diff --git a/lib/features/composer/presentation/composer_view.dart b/lib/features/composer/presentation/composer_view.dart index 1013c4256..c011f0d60 100644 --- a/lib/features/composer/presentation/composer_view.dart +++ b/lib/features/composer/presentation/composer_view.dart @@ -3,7 +3,6 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:html_editor_enhanced/html_editor.dart'; -import 'package:model/email/email_action_type.dart'; import 'package:tmail_ui_user/features/composer/presentation/composer_controller.dart'; import 'package:tmail_ui_user/features/composer/presentation/widgets/email_address_composer_widget_builder.dart'; import 'package:tmail_ui_user/features/composer/presentation/widgets/top_bar_composer_widget_builder.dart'; @@ -13,35 +12,36 @@ class ComposerView extends GetWidget { final responsiveUtils = Get.find(); final imagePaths = Get.find(); - final htmlMessagePurifier = Get.find(); final keyboardUtils = Get.find(); @override Widget build(BuildContext context) { - return Scaffold( - resizeToAvoidBottomInset: false, - backgroundColor: AppColor.primaryLightColor, - body: SafeArea( - right: false, - left: false, - child: Container( - margin: EdgeInsets.zero, - alignment: Alignment.topCenter, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - _buildTopBar(context), - Expanded( - child: Container( + return GestureDetector( + onTap: () => FocusManager.instance.primaryFocus?.unfocus(), + child: Scaffold( + resizeToAvoidBottomInset: false, + backgroundColor: AppColor.primaryLightColor, + body: SafeArea( + right: false, + left: false, + child: Container( + margin: EdgeInsets.zero, + alignment: Alignment.topCenter, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.max, + children: [ + _buildTopBar(context), + Expanded(child: Container( color: AppColor.bgComposer, margin: EdgeInsets.zero, alignment: Alignment.topCenter, - child: _buildEmailBody(context))) + child: _buildBodyComposer(context))) ]) - ) - ), + ) + ), + ) ); } @@ -55,7 +55,7 @@ class ComposerView extends GetWidget { ); } - Widget _buildEmailHeaderField(BuildContext context) { + Widget _buildEmailHeader(BuildContext context) { return Container( margin: EdgeInsets.zero, padding: EdgeInsets.only(top: 20), @@ -67,12 +67,7 @@ class ComposerView extends GetWidget { padding: EdgeInsets.symmetric(horizontal: 24), child: _buildEmailAddress(context)), _buildSubjectEmail(context), - Container( - margin: EdgeInsets.zero, - padding: EdgeInsets.zero, - height: 1, - color: AppColor.dividerColor, - ) + Divider(color: AppColor.dividerColor, height: 1) ], ), ); @@ -97,55 +92,55 @@ class ComposerView extends GetWidget { Widget _buildSubjectEmail(BuildContext context) { return Padding( padding: EdgeInsets.only(left: 24, right: 24, bottom: 10, top: 8), - child: Obx(() => TextFieldBuilder() - .key(Key('subject_email_input')) - .textInputAction(TextInputAction.newline) - .maxLines(null) - .onChange((value) => controller.setSubjectEmail(value)) - .textStyle(TextStyle(color: AppColor.nameUserColor, fontSize: 14, fontWeight: FontWeight.w500)) - .textDecoration(InputDecoration( - hintText: AppLocalizations.of(context).subject_email, - hintStyle: TextStyle(color: AppColor.baseTextColor, fontSize: 14, fontWeight: FontWeight.w500), - contentPadding: EdgeInsets.zero, - filled: true, - border: InputBorder.none, - fillColor: AppColor.bgComposer)) - .setText(controller.getEmailSubject(context)) - .build()), + child: (TextFieldBuilder() + ..key(Key('subject_email_input')) + ..textInputAction(TextInputAction.newline) + ..maxLines(null) + ..onChange((value) => controller.setSubjectEmail(value)) + ..textStyle(TextStyle(color: AppColor.nameUserColor, fontSize: 14, fontWeight: FontWeight.w500)) + ..textDecoration(InputDecoration( + hintText: AppLocalizations.of(context).subject_email, + hintStyle: TextStyle(color: AppColor.baseTextColor, fontSize: 14, fontWeight: FontWeight.w500), + contentPadding: EdgeInsets.zero, + filled: true, + border: InputBorder.none, + fillColor: AppColor.bgComposer)) + ..addController(controller.subjectEmailInputController)) + .build() ); } - Widget _buildEmailBody(BuildContext context) { + Widget _buildBodyComposer(BuildContext context) { return SingleChildScrollView( physics: ClampingScrollPhysics(), child: Column( children: [ - _buildEmailHeaderField(context), + _buildEmailHeader(context), Padding( padding: EdgeInsets.only(bottom: 30, top: 16, left: 16, right: 16), - child: _buildEmailBodyEditorQuoted(context), + child: _buildComposerEditer(context), ) ] ) ); } - Widget _buildEmailBodyEditorQuoted(BuildContext context) { - return Obx(() => HtmlEditor( + Widget _buildComposerEditer(BuildContext context) { + return HtmlEditor( key: Key('email_body_editor_quoted'), - controller: controller.htmlEditorController, + controller: controller.composerEditorController, htmlEditorOptions: HtmlEditorOptions( hint: AppLocalizations.of(context).hint_content_email_composer, - initialText: controller.getEmailActionType() != EmailActionType.compose - ? controller.getBodyEmailQuotedAsHtml(context, htmlMessagePurifier) - : null, shouldEnsureVisible: true), otherOptions: OtherOptions(decoration: BoxDecoration()), callbacks: Callbacks( onFocus: () { - FocusScope.of(context).unfocus(); + FocusManager.instance.primaryFocus?.unfocus(); + }, + onInit: () { + controller.initContentEmail(); } ), - )); + ); } } \ No newline at end of file diff --git a/lib/features/email/presentation/email_controller.dart b/lib/features/email/presentation/email_controller.dart index 3afdcb095..971dc3cd0 100644 --- a/lib/features/email/presentation/email_controller.dart +++ b/lib/features/email/presentation/email_controller.dart @@ -66,9 +66,9 @@ class EmailController extends BaseController { } @override - void dispose() { - super.dispose(); + void onClose() { mailboxDashBoardController.selectedEmail.close(); + super.onClose(); } void _getEmailContentAction(AccountId accountId, EmailId emailId) async { diff --git a/lib/features/login/presentation/login_view.dart b/lib/features/login/presentation/login_view.dart index 1f0109dd2..9cab84be4 100644 --- a/lib/features/login/presentation/login_view.dart +++ b/lib/features/login/presentation/login_view.dart @@ -91,14 +91,14 @@ class LoginView extends GetWidget { padding: EdgeInsets.only(bottom: 16), child: Container( width: responsiveUtils.getWidthLoginTextField(context), - child: TextFieldBuilder() - .key(Key('login_url_input')) - .onChange((value) => loginController.setUrlText(value)) - .textInputAction(TextInputAction.next) - .textDecoration(LoginInputDecorationBuilder() - .setLabelText(AppLocalizations.of(context).prefix_https) - .setPrefixText(AppLocalizations.of(context).prefix_https) - .build()) + child: (TextFieldBuilder() + ..key(Key('login_url_input')) + ..onChange((value) => loginController.setUrlText(value)) + ..textInputAction(TextInputAction.next) + ..textDecoration(LoginInputDecorationBuilder() + .setLabelText(AppLocalizations.of(context).prefix_https) + .setPrefixText(AppLocalizations.of(context).prefix_https) + .build())) .build())); } @@ -107,14 +107,14 @@ class LoginView extends GetWidget { padding: EdgeInsets.only(bottom: 16), child: Container( width: responsiveUtils.getWidthLoginTextField(context), - child: TextFieldBuilder() - .key(Key('login_username_input')) - .onChange((value) => loginController.setUserNameText(value)) - .textInputAction(TextInputAction.next) - .textDecoration(LoginInputDecorationBuilder() - .setLabelText(AppLocalizations.of(context).username) - .setHintText(AppLocalizations.of(context).username) - .build()) + child: (TextFieldBuilder() + ..key(Key('login_username_input')) + ..onChange((value) => loginController.setUserNameText(value)) + ..textInputAction(TextInputAction.next) + ..textDecoration(LoginInputDecorationBuilder() + .setLabelText(AppLocalizations.of(context).username) + .setHintText(AppLocalizations.of(context).username) + .build())) .build())); } @@ -123,15 +123,15 @@ class LoginView extends GetWidget { padding: EdgeInsets.only(bottom: 40), child: Container( width: responsiveUtils.getWidthLoginTextField(context), - child: TextFieldBuilder() - .key(Key('login_password_input')) - .obscureText(true) - .onChange((value) => loginController.setPasswordText(value)) - .textInputAction(TextInputAction.done) - .textDecoration(LoginInputDecorationBuilder() - .setLabelText(AppLocalizations.of(context).password) - .setHintText(AppLocalizations.of(context).password) - .build()) + child: (TextFieldBuilder() + ..key(Key('login_password_input')) + ..obscureText(true) + ..onChange((value) => loginController.setPasswordText(value)) + ..textInputAction(TextInputAction.done) + ..textDecoration(LoginInputDecorationBuilder() + .setLabelText(AppLocalizations.of(context).password) + .setHintText(AppLocalizations.of(context).password) + .build())) .build())); } diff --git a/lib/features/mailbox/presentation/mailbox_controller.dart b/lib/features/mailbox/presentation/mailbox_controller.dart index 991c169fe..646aaa322 100644 --- a/lib/features/mailbox/presentation/mailbox_controller.dart +++ b/lib/features/mailbox/presentation/mailbox_controller.dart @@ -57,9 +57,9 @@ class MailboxController extends BaseController { } @override - void dispose() { - super.dispose(); + void onClose() { mailboxDashBoardController.accountId.close(); + super.onClose(); } void refreshGetAllMailboxAction() { diff --git a/lib/features/thread/presentation/thread_controller.dart b/lib/features/thread/presentation/thread_controller.dart index 18e7e303f..8d8fe5f20 100644 --- a/lib/features/thread/presentation/thread_controller.dart +++ b/lib/features/thread/presentation/thread_controller.dart @@ -80,10 +80,10 @@ class ThreadController extends BaseController { } @override - void dispose() { + void onClose() { mailboxDashBoardController.selectedMailbox.close(); listEmailController.dispose(); - super.dispose(); + super.onClose(); } @override