TF-2311 Sync use variables in BaseController to avoid wasting memory

Signed-off-by: dab246 <tdvu@linagora.com>

Signed-off-by: dab246 <tdvu@linagora.com>
(cherry picked from commit 21ac80615f7bc9e832fd72cb8ae6875c967d3cea)
This commit is contained in:
dab246
2023-11-14 17:33:17 +07:00
committed by Dat Vu
parent 4ff601b4fc
commit fb47832225
57 changed files with 727 additions and 958 deletions
@@ -86,7 +86,6 @@ import 'package:tmail_ui_user/features/upload/domain/usecases/local_file_picker_
import 'package:tmail_ui_user/features/upload/presentation/controller/upload_controller.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
import 'package:uuid/uuid.dart';
import 'package:universal_html/html.dart' as html;
class ComposerController extends BaseController {
@@ -94,10 +93,6 @@ class ComposerController extends BaseController {
final mailboxDashBoardController = Get.find<MailboxDashBoardController>();
final richTextMobileTabletController = Get.find<RichTextMobileTabletController>();
final networkConnectionController = Get.find<NetworkConnectionController>();
final _appToast = Get.find<AppToast>();
final _imagePaths = Get.find<ImagePaths>();
final _responsiveUtils = Get.find<ResponsiveUtils>();
final _uuid = Get.find<Uuid>();
final _dynamicUrlInterceptors = Get.find<DynamicUrlInterceptors>();
final expandModeAttachments = ExpandMode.EXPAND.obs;
@@ -726,7 +721,7 @@ class ComposerController extends BaseController {
final inReplyTo = _generateInReplyTo(arguments);
final references = _generateReferences(arguments);
final generatePartId = PartId(_uuid.v1());
final generatePartId = PartId(uuid.v1());
return Email(
mailboxIds: mailboxIds.isNotEmpty ? mailboxIds : null,
@@ -828,7 +823,7 @@ class ComposerController extends BaseController {
AppLocalizations.of(context).add_recipients,
onConfirmAction: () => {isSendEmailLoading.value = false},
title: AppLocalizations.of(context).sending_failed,
icon: SvgPicture.asset(_imagePaths.icSendToastError, fit: BoxFit.fill),
icon: SvgPicture.asset(imagePaths.icSendToastError, fit: BoxFit.fill),
hasCancelButton: false);
return;
}
@@ -848,7 +843,7 @@ class ComposerController extends BaseController {
isSendEmailLoading.value = false;
},
title: AppLocalizations.of(context).sending_failed,
icon: SvgPicture.asset(_imagePaths.icSendToastError, fit: BoxFit.fill),
icon: SvgPicture.asset(imagePaths.icSendToastError, fit: BoxFit.fill),
hasCancelButton: false);
return;
}
@@ -860,7 +855,7 @@ class ComposerController extends BaseController {
onConfirmAction: () => _handleSendMessages(context),
onCancelAction: () => {isSendEmailLoading.value = false},
title: AppLocalizations.of(context).empty_subject,
icon: SvgPicture.asset(_imagePaths.icEmpty, fit: BoxFit.fill),
icon: SvgPicture.asset(imagePaths.icEmpty, fit: BoxFit.fill),
);
return;
}
@@ -872,7 +867,7 @@ class ComposerController extends BaseController {
AppLocalizations.of(context).got_it,
onConfirmAction: () => {isSendEmailLoading.value = false},
title: AppLocalizations.of(context).sending_failed,
icon: SvgPicture.asset(_imagePaths.icSendToastError, fit: BoxFit.fill),
icon: SvgPicture.asset(imagePaths.icSendToastError, fit: BoxFit.fill),
hasCancelButton: false);
return;
}
@@ -885,7 +880,7 @@ class ComposerController extends BaseController {
AppLocalizations.of(context).got_it,
onConfirmAction: () => {isSendEmailLoading.value = false},
title: AppLocalizations.of(context).sending_failed,
icon: SvgPicture.asset(_imagePaths.icSendToastError, fit: BoxFit.fill),
icon: SvgPicture.asset(imagePaths.icSendToastError, fit: BoxFit.fill),
hasCancelButton: false);
return;
}
@@ -957,7 +952,7 @@ class ComposerController extends BaseController {
final mailboxRequest = mailboxDashBoardController.outboxMailbox?.id == null
? CreateNewMailboxRequest(
Id(_uuid.v1()),
Id(uuid.v1()),
MailboxName(PresentationMailbox.outboxRole.inCaps)
)
: null;
@@ -985,7 +980,7 @@ class ComposerController extends BaseController {
},
onCancelAction: _closeComposerAction,
title: AppLocalizations.of(context).youAreInOfflineMode,
icon: SvgPicture.asset(_imagePaths.icDialogOfflineMode),
icon: SvgPicture.asset(imagePaths.icDialogOfflineMode),
alignCenter: true,
messageStyle: const TextStyle(
color: AppColor.colorTitleSendingItem,
@@ -1124,7 +1119,7 @@ class ComposerController extends BaseController {
void _pickFileFailure(Failure failure) {
if (failure is LocalFilePickerFailure) {
if (currentOverlayContext != null && currentContext != null) {
_appToast.showToastErrorMessage(
appToast.showToastErrorMessage(
currentOverlayContext!,
AppLocalizations.of(currentContext!).can_not_upload_this_file_as_attachments);
}
@@ -1765,7 +1760,7 @@ class ComposerController extends BaseController {
void insertImage(BuildContext context, double maxWith) async {
clearFocusEditor(context);
if (_responsiveUtils.isMobile(context)) {
if (responsiveUtils.isMobile(context)) {
maxWithEditor = maxWith - 40;
} else {
maxWithEditor = maxWith - 120;
@@ -1779,7 +1774,7 @@ class ComposerController extends BaseController {
}
} else {
if (context.mounted) {
_appToast.showToastErrorMessage(context, AppLocalizations.of(context).cannotSelectThisImage);
appToast.showToastErrorMessage(context, AppLocalizations.of(context).cannotSelectThisImage);
}
}
}
@@ -1912,7 +1907,7 @@ class ComposerController extends BaseController {
BuildContext context,
) {
scrollController.jumpTo(
realCoordinateY - (_responsiveUtils.isLandscapeMobile(context) ? 0 : headerEditorMobileHeight / 2),
realCoordinateY - (responsiveUtils.isLandscapeMobile(context) ? 0 : headerEditorMobileHeight / 2),
);
}
@@ -1978,7 +1973,7 @@ class ComposerController extends BaseController {
) async {
log('ComposerController::handleImageUploadSuccess:NAME: ${fileUpload.name} | TYPE: ${fileUpload.type} | SIZE: ${fileUpload.size}');
if (fileUpload.base64 == null) {
_appToast.showToastErrorMessage(
appToast.showToastErrorMessage(
context,
AppLocalizations.of(context).can_not_upload_this_file_as_attachments
);
@@ -1990,7 +1985,7 @@ class ComposerController extends BaseController {
if (fileInfo != null) {
_uploadInlineAttachmentsAction(fileInfo);
} else if (context.mounted) {
_appToast.showToastErrorMessage(
appToast.showToastErrorMessage(
context,
AppLocalizations.of(context).can_not_upload_this_file_as_attachments
);
@@ -2000,7 +1995,7 @@ class ComposerController extends BaseController {
if (fileInfo != null) {
_addAttachmentFromDragAndDrop(fileInfo: fileInfo);
} else if (context.mounted) {
_appToast.showToastErrorMessage(
appToast.showToastErrorMessage(
context,
AppLocalizations.of(context).can_not_upload_this_file_as_attachments
);
@@ -2015,7 +2010,7 @@ class ComposerController extends BaseController {
String? base64Str,
}) {
logError('ComposerController::handleImageUploadFailure:fileUpload: $fileUpload | uploadError: $uploadError');
_appToast.showToastErrorMessage(
appToast.showToastErrorMessage(
context,
'${AppLocalizations.of(context).can_not_upload_this_file_as_attachments}. (${uploadError.name})'
);
@@ -2083,7 +2078,7 @@ class ComposerController extends BaseController {
var contentHtml = '';
if (PlatformInfo.isWeb) {
if (_responsiveUtils.isDesktop(context) &&
if (responsiveUtils.isDesktop(context) &&
screenDisplayMode.value == ScreenDisplayMode.minimize) {
contentHtml = _textEditorWeb ?? '';
} else {
@@ -2176,7 +2171,7 @@ class ComposerController extends BaseController {
(
FromComposerBottomSheetBuilder(
context,
_imagePaths,
imagePaths,
listFromIdentities,
scrollControllerIdentities,
searchIdentitiesInputController
@@ -1,5 +1,3 @@
import 'package:core/presentation/resources/image_paths.dart';
import 'package:core/presentation/utils/responsive_utils.dart';
import 'package:core/presentation/views/context_menu/simple_context_menu_action_builder.dart';
import 'package:core/presentation/views/responsive/responsive_widget.dart';
import 'package:file_picker/file_picker.dart';
@@ -31,15 +29,12 @@ import 'package:tmail_ui_user/main/routes/route_navigation.dart';
class ComposerView extends GetWidget<ComposerController> {
final _responsiveUtils = Get.find<ResponsiveUtils>();
final _imagePaths = Get.find<ImagePaths>();
ComposerView({Key? key}) : super(key: key);
const ComposerView({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ResponsiveWidget(
responsiveUtils: _responsiveUtils,
responsiveUtils: controller.responsiveUtils,
mobile: MobileContainerView(
keyboardRichTextController: controller.keyboardRichTextController,
onCloseViewAction: () => controller.saveToDraftAndClose(context, canPop: false),
@@ -55,13 +50,13 @@ class ComposerView extends GetWidget<ComposerController> {
: null,
backgroundColor: MobileAppBarComposerWidgetStyle.backgroundColor,
childBuilder: (context) => SafeArea(
left: !_responsiveUtils.isLandscapeMobile(context),
right: !_responsiveUtils.isLandscapeMobile(context),
left: !controller.responsiveUtils.isLandscapeMobile(context),
right: !controller.responsiveUtils.isLandscapeMobile(context),
child: Container(
color: ComposerStyle.mobileBackgroundColor,
child: Column(
children: [
if (_responsiveUtils.isLandscapeMobile(context))
if (controller.responsiveUtils.isLandscapeMobile(context))
Obx(() => LandscapeAppBarComposerWidget(
isSendButtonEnabled: controller.isEnableEmailSendButton.value,
onCloseViewAction: () => controller.saveToDraftAndClose(context),
@@ -103,8 +98,8 @@ class ComposerView extends GetWidget<ComposerController> {
if (controller.fromRecipientState.value == PrefixRecipientState.enabled)
FromComposerMobileWidget(
selectedIdentity: controller.identitySelected.value,
imagePaths: _imagePaths,
responsiveUtils: _responsiveUtils,
imagePaths: controller.imagePaths,
responsiveUtils: controller.responsiveUtils,
margin: ComposerStyle.mobileRecipientMargin,
padding: ComposerStyle.mobileRecipientPadding,
onTap: () => controller.openSelectIdentityBottomSheet(context)
@@ -252,7 +247,7 @@ class ComposerView extends GetWidget<ComposerController> {
items: controller.listFromIdentities,
itemSelected: controller.identitySelected.value,
dropdownKey: controller.identityDropdownKey,
imagePaths: _imagePaths,
imagePaths: controller.imagePaths,
padding: ComposerStyle.mobileRecipientPadding,
margin: ComposerStyle.mobileRecipientMargin,
onChangeIdentity: controller.onChangeIdentity,
@@ -390,7 +385,7 @@ class ComposerView extends GetWidget<ComposerController> {
Widget _pickPhotoAndVideoAction(BuildContext context) {
return (SimpleContextMenuActionBuilder(
const Key('pick_photo_and_video_context_menu_action'),
SvgPicture.asset(_imagePaths.icPhotoLibrary, width: 24, height: 24, fit: BoxFit.fill),
SvgPicture.asset(controller.imagePaths.icPhotoLibrary, width: 24, height: 24, fit: BoxFit.fill),
AppLocalizations.of(context).photos_and_videos)
..onActionClick((_) => controller.openFilePickerByType(context, FileType.media)))
.build();
@@ -399,7 +394,7 @@ class ComposerView extends GetWidget<ComposerController> {
Widget _browseFileAction(BuildContext context) {
return (SimpleContextMenuActionBuilder(
const Key('browse_file_context_menu_action'),
SvgPicture.asset(_imagePaths.icMore, width: 24, height: 24, fit: BoxFit.fill),
SvgPicture.asset(controller.imagePaths.icMore, width: 24, height: 24, fit: BoxFit.fill),
AppLocalizations.of(context).browse)
..onActionClick((_) => controller.openFilePickerByType(context, FileType.any)))
.build();
@@ -410,11 +405,11 @@ class ComposerView extends GetWidget<ComposerController> {
PopupMenuItem(
padding: EdgeInsets.zero,
child: PopupItemWidget(
_imagePaths.icReadReceipt,
controller.imagePaths.icReadReceipt,
AppLocalizations.of(context).requestReadReceipt,
styleName: ComposerStyle.popupItemTextStyle,
padding: ComposerStyle.popupItemPadding,
selectedIcon: _imagePaths.icFilterSelected,
selectedIcon: controller.imagePaths.icFilterSelected,
isSelected: controller.hasRequestReadReceipt.value,
onCallbackAction: () {
popBack();
@@ -430,12 +425,12 @@ class ComposerView extends GetWidget<ComposerController> {
PopupMenuItem(
padding: EdgeInsets.zero,
child: PopupItemWidget(
_imagePaths.icReadReceipt,
controller.imagePaths.icReadReceipt,
AppLocalizations.of(context).requestReadReceipt,
styleName: ComposerStyle.popupItemTextStyle,
padding: ComposerStyle.popupItemPadding,
colorIcon: ComposerStyle.popupItemIconColor,
selectedIcon: _imagePaths.icFilterSelected,
selectedIcon: controller.imagePaths.icFilterSelected,
isSelected: controller.hasRequestReadReceipt.value,
onCallbackAction: () {
popBack();
@@ -446,7 +441,7 @@ class ComposerView extends GetWidget<ComposerController> {
PopupMenuItem(
padding: EdgeInsets.zero,
child: PopupItemWidget(
_imagePaths.icSaveToDraft,
controller.imagePaths.icSaveToDraft,
AppLocalizations.of(context).saveAsDraft,
colorIcon: ComposerStyle.popupItemIconColor,
styleName: ComposerStyle.popupItemTextStyle,
@@ -460,7 +455,7 @@ class ComposerView extends GetWidget<ComposerController> {
PopupMenuItem(
padding: EdgeInsets.zero,
child: PopupItemWidget(
_imagePaths.icDeleteMailbox,
controller.imagePaths.icDeleteMailbox,
AppLocalizations.of(context).delete,
styleName: ComposerStyle.popupItemTextStyle,
padding: ComposerStyle.popupItemPadding,
@@ -1,5 +1,3 @@
import 'package:core/presentation/resources/image_paths.dart';
import 'package:core/presentation/utils/responsive_utils.dart';
import 'package:core/presentation/views/responsive/responsive_widget.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
@@ -30,15 +28,12 @@ import 'package:tmail_ui_user/main/routes/route_navigation.dart';
class ComposerView extends GetWidget<ComposerController> {
final _responsiveUtils = Get.find<ResponsiveUtils>();
final _imagePaths = Get.find<ImagePaths>();
ComposerView({Key? key}) : super(key: key);
const ComposerView({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ResponsiveWidget(
responsiveUtils: _responsiveUtils,
responsiveUtils: controller.responsiveUtils,
mobile: MobileResponsiveContainerView(
childBuilder: (context, constraints) {
return Column(
@@ -67,7 +62,7 @@ class ComposerView extends GetWidget<ComposerController> {
maxHeight: ComposerStyle.getMaxHeightEmailAddressWidget(
context,
constraints,
_responsiveUtils
controller.responsiveUtils
)
),
child: SingleChildScrollView(
@@ -79,8 +74,8 @@ class ComposerView extends GetWidget<ComposerController> {
message: controller.identitySelected.value?.email ?? '',
child: FromComposerMobileWidget(
selectedIdentity: controller.identitySelected.value,
imagePaths: _imagePaths,
responsiveUtils: _responsiveUtils,
imagePaths: controller.imagePaths,
responsiveUtils: controller.responsiveUtils,
margin: ComposerStyle.mobileRecipientMargin,
padding: ComposerStyle.mobileRecipientPadding,
onTap: () => controller.openSelectIdentityBottomSheet(context)
@@ -247,7 +242,7 @@ class ComposerView extends GetWidget<ComposerController> {
maxHeight: ComposerStyle.getMaxHeightEmailAddressWidget(
context,
constraints,
_responsiveUtils
controller.responsiveUtils
)
),
child: SingleChildScrollView(
@@ -259,7 +254,7 @@ class ComposerView extends GetWidget<ComposerController> {
items: controller.listFromIdentities,
itemSelected: controller.identitySelected.value,
dropdownKey: controller.identityDropdownKey,
imagePaths: _imagePaths,
imagePaths: controller.imagePaths,
padding: ComposerStyle.desktopRecipientPadding,
margin: ComposerStyle.desktopRecipientMargin,
onChangeIdentity: controller.onChangeIdentity,
@@ -477,7 +472,7 @@ class ComposerView extends GetWidget<ComposerController> {
maxHeight: ComposerStyle.getMaxHeightEmailAddressWidget(
context,
constraints,
_responsiveUtils
controller.responsiveUtils
)
),
child: SingleChildScrollView(
@@ -489,7 +484,7 @@ class ComposerView extends GetWidget<ComposerController> {
items: controller.listFromIdentities,
itemSelected: controller.identitySelected.value,
dropdownKey: controller.identityDropdownKey,
imagePaths: _imagePaths,
imagePaths: controller.imagePaths,
padding: ComposerStyle.tabletRecipientPadding,
margin: ComposerStyle.tabletRecipientMargin,
onChangeIdentity: controller.onChangeIdentity,
@@ -683,11 +678,11 @@ class ComposerView extends GetWidget<ComposerController> {
PopupMenuItem(
padding: EdgeInsets.zero,
child: PopupItemWidget(
_imagePaths.icReadReceipt,
controller.imagePaths.icReadReceipt,
AppLocalizations.of(context).requestReadReceipt,
styleName: ComposerStyle.popupItemTextStyle,
padding: ComposerStyle.popupItemPadding,
selectedIcon: _imagePaths.icFilterSelected,
selectedIcon: controller.imagePaths.icFilterSelected,
isSelected: controller.hasRequestReadReceipt.value,
onCallbackAction: () {
popBack();
@@ -703,12 +698,12 @@ class ComposerView extends GetWidget<ComposerController> {
PopupMenuItem(
padding: EdgeInsets.zero,
child: PopupItemWidget(
_imagePaths.icStyleCodeView,
controller.imagePaths.icStyleCodeView,
AppLocalizations.of(context).embedCode,
styleName: ComposerStyle.popupItemTextStyle,
colorIcon: ComposerStyle.popupItemIconColor,
padding: ComposerStyle.popupItemPadding,
selectedIcon: _imagePaths.icFilterSelected,
selectedIcon: controller.imagePaths.icFilterSelected,
isSelected: controller.richTextWebController.codeViewEnabled,
onCallbackAction: () {
popBack();
@@ -719,12 +714,12 @@ class ComposerView extends GetWidget<ComposerController> {
PopupMenuItem(
padding: EdgeInsets.zero,
child: PopupItemWidget(
_imagePaths.icReadReceipt,
controller.imagePaths.icReadReceipt,
AppLocalizations.of(context).requestReadReceipt,
styleName: ComposerStyle.popupItemTextStyle,
padding: ComposerStyle.popupItemPadding,
colorIcon: ComposerStyle.popupItemIconColor,
selectedIcon: _imagePaths.icFilterSelected,
selectedIcon: controller.imagePaths.icFilterSelected,
isSelected: controller.hasRequestReadReceipt.value,
onCallbackAction: () {
popBack();
@@ -735,7 +730,7 @@ class ComposerView extends GetWidget<ComposerController> {
PopupMenuItem(
padding: EdgeInsets.zero,
child: PopupItemWidget(
_imagePaths.icSaveToDraft,
controller.imagePaths.icSaveToDraft,
AppLocalizations.of(context).saveAsDraft,
colorIcon: ComposerStyle.popupItemIconColor,
styleName: ComposerStyle.popupItemTextStyle,
@@ -749,7 +744,7 @@ class ComposerView extends GetWidget<ComposerController> {
PopupMenuItem(
padding: EdgeInsets.zero,
child: PopupItemWidget(
_imagePaths.icDeleteMailbox,
controller.imagePaths.icDeleteMailbox,
AppLocalizations.of(context).delete,
styleName: ComposerStyle.popupItemTextStyle,
padding: ComposerStyle.popupItemPadding,