Fix composer controller not deleted from GetX when click Discard Changes button

This commit is contained in:
dab246
2024-04-25 01:18:45 +07:00
committed by Dat H. Pham
parent 5f450f2c31
commit 32cb559fe0
3 changed files with 59 additions and 42 deletions
@@ -22,6 +22,7 @@ mixin MessageDialogActionMixin {
bool showAsBottomSheet = false, bool showAsBottomSheet = false,
bool alignCenter = false, bool alignCenter = false,
bool outsideDismissible = true, bool outsideDismissible = true,
bool autoPerformPopBack = true,
List<TextSpan>? listTextSpan, List<TextSpan>? listTextSpan,
Widget? icon, Widget? icon,
TextStyle? titleStyle, TextStyle? titleStyle,
@@ -59,13 +60,17 @@ mixin MessageDialogActionMixin {
..styleTextCancelButton(cancelStyle ?? const TextStyle(fontSize: 17, fontWeight: FontWeight.w500, color: AppColor.colorTextButton)) ..styleTextCancelButton(cancelStyle ?? const TextStyle(fontSize: 17, fontWeight: FontWeight.w500, color: AppColor.colorTextButton))
..styleTextConfirmButton(actionStyle ?? const TextStyle(fontSize: 17, fontWeight: FontWeight.w500, color: Colors.white)) ..styleTextConfirmButton(actionStyle ?? const TextStyle(fontSize: 17, fontWeight: FontWeight.w500, color: Colors.white))
..onConfirmButtonAction(actionName, () { ..onConfirmButtonAction(actionName, () {
popBack(); if (autoPerformPopBack) {
popBack();
}
onConfirmAction?.call(); onConfirmAction?.call();
}) })
..onCancelButtonAction( ..onCancelButtonAction(
hasCancelButton ? cancelTitle ?? AppLocalizations.of(context).cancel : '', hasCancelButton ? cancelTitle ?? AppLocalizations.of(context).cancel : '',
() { () {
popBack(); if (autoPerformPopBack) {
popBack();
}
onCancelAction?.call(); onCancelAction?.call();
} }
) )
@@ -106,13 +111,17 @@ mixin MessageDialogActionMixin {
..styleTextCancelButton(cancelStyle ?? const TextStyle(fontSize: 17, fontWeight: FontWeight.w500, color: AppColor.colorTextButton)) ..styleTextCancelButton(cancelStyle ?? const TextStyle(fontSize: 17, fontWeight: FontWeight.w500, color: AppColor.colorTextButton))
..styleTextConfirmButton(actionStyle ?? const TextStyle(fontSize: 17, fontWeight: FontWeight.w500, color: Colors.white)) ..styleTextConfirmButton(actionStyle ?? const TextStyle(fontSize: 17, fontWeight: FontWeight.w500, color: Colors.white))
..onConfirmButtonAction(actionName, () { ..onConfirmButtonAction(actionName, () {
popBack(); if (autoPerformPopBack) {
popBack();
}
onConfirmAction?.call(); onConfirmAction?.call();
}) })
..onCancelButtonAction( ..onCancelButtonAction(
hasCancelButton ? cancelTitle ?? AppLocalizations.of(context).cancel : '', hasCancelButton ? cancelTitle ?? AppLocalizations.of(context).cancel : '',
() { () {
popBack(); if (autoPerformPopBack) {
popBack();
}
onCancelAction?.call(); onCancelAction?.call();
} }
) )
@@ -136,12 +145,16 @@ mixin MessageDialogActionMixin {
..onCancelAction( ..onCancelAction(
cancelTitle ?? AppLocalizations.of(context).cancel, cancelTitle ?? AppLocalizations.of(context).cancel,
() { () {
popBack(); if (autoPerformPopBack) {
popBack();
}
onCancelAction?.call(); onCancelAction?.call();
} }
) )
..onConfirmAction(actionName, () { ..onConfirmAction(actionName, () {
popBack(); if (autoPerformPopBack) {
popBack();
}
onConfirmAction?.call(); onConfirmAction?.call();
})).show(); })).show();
} }
@@ -167,13 +180,17 @@ mixin MessageDialogActionMixin {
..styleTextCancelButton(cancelStyle ?? const TextStyle(fontSize: 17, fontWeight: FontWeight.w500, color: AppColor.colorTextButton)) ..styleTextCancelButton(cancelStyle ?? const TextStyle(fontSize: 17, fontWeight: FontWeight.w500, color: AppColor.colorTextButton))
..styleTextConfirmButton(actionStyle ?? const TextStyle(fontSize: 17, fontWeight: FontWeight.w500, color: Colors.white)) ..styleTextConfirmButton(actionStyle ?? const TextStyle(fontSize: 17, fontWeight: FontWeight.w500, color: Colors.white))
..onConfirmButtonAction(actionName, () { ..onConfirmButtonAction(actionName, () {
popBack(); if (autoPerformPopBack) {
popBack();
}
onConfirmAction?.call(); onConfirmAction?.call();
}) })
..onCancelButtonAction( ..onCancelButtonAction(
hasCancelButton ? cancelTitle ?? AppLocalizations.of(context).cancel : '', hasCancelButton ? cancelTitle ?? AppLocalizations.of(context).cancel : '',
() { () {
popBack(); if (autoPerformPopBack) {
popBack();
}
onCancelAction?.call(); onCancelAction?.call();
} }
) )
@@ -770,6 +770,7 @@ class ComposerController extends BaseController with DragDropFileMixin {
AppLocalizations.of(context).message_dialog_send_email_without_a_subject, AppLocalizations.of(context).message_dialog_send_email_without_a_subject,
AppLocalizations.of(context).send_anyway, AppLocalizations.of(context).send_anyway,
onConfirmAction: () => _handleSendMessages(context), onConfirmAction: () => _handleSendMessages(context),
autoPerformPopBack: false,
title: AppLocalizations.of(context).empty_subject, title: AppLocalizations.of(context).empty_subject,
showAsBottomSheet: true, showAsBottomSheet: true,
icon: SvgPicture.asset(imagePaths.icEmpty, fit: BoxFit.fill), icon: SvgPicture.asset(imagePaths.icEmpty, fit: BoxFit.fill),
@@ -824,10 +825,12 @@ class ComposerController extends BaseController with DragDropFileMixin {
) { ) {
log('ComposerController::_handleSendMessages: SESSION or ACCOUNT_ID or ARGUMENTS is NULL'); log('ComposerController::_handleSendMessages: SESSION or ACCOUNT_ID or ARGUMENTS is NULL');
_sendButtonState = ButtonState.enabled; _sendButtonState = ButtonState.enabled;
_closeComposerAction(); _closeComposerAction(closeOverlays: true);
return; return;
} }
popBack();
final emailContent = await _getContentInEditor(); final emailContent = await _getContentInEditor();
final cancelToken = CancelToken(); final cancelToken = CancelToken();
final resultState = await _showSendingMessageDialog( final resultState = await _showSendingMessageDialog(
@@ -841,7 +844,7 @@ class ComposerController extends BaseController with DragDropFileMixin {
} else if (resultState is SendEmailFailure && resultState.exception is SendingEmailCanceledException) { } else if (resultState is SendEmailFailure && resultState.exception is SendingEmailCanceledException) {
_sendButtonState = ButtonState.enabled; _sendButtonState = ButtonState.enabled;
} else if ((resultState is SendEmailFailure || resultState is GenerateEmailFailure) && context.mounted) { } else if ((resultState is SendEmailFailure || resultState is GenerateEmailFailure) && context.mounted) {
_showConfirmDialogWhenSendMessageFailure( await _showConfirmDialogWhenSendMessageFailure(
context: context, context: context,
failure: resultState failure: resultState
); );
@@ -900,27 +903,27 @@ class ComposerController extends BaseController with DragDropFileMixin {
cancelToken?.cancel([SendingEmailCanceledException()]); cancelToken?.cancel([SendingEmailCanceledException()]);
} }
void _showConfirmDialogWhenSendMessageFailure({ Future<void> _showConfirmDialogWhenSendMessageFailure({
required BuildContext context, required BuildContext context,
required FeatureFailure failure required FeatureFailure failure
}) { }) async {
showConfirmDialogAction( await showConfirmDialogAction(
context, context,
title: '', title: '',
AppLocalizations.of(context).warningMessageWhenSendEmailFailure, AppLocalizations.of(context).warningMessageWhenSendEmailFailure,
AppLocalizations.of(context).edit, AppLocalizations.of(context).edit,
cancelTitle: AppLocalizations.of(context).closeAnyway, cancelTitle: AppLocalizations.of(context).closeAnyway,
alignCenter: true, alignCenter: true,
outsideDismissible: false,
autoPerformPopBack: false,
onConfirmAction: () { onConfirmAction: () {
_sendButtonState = ButtonState.enabled; _sendButtonState = ButtonState.enabled;
popBack();
_autoFocusFieldWhenLauncher(); _autoFocusFieldWhenLauncher();
}, },
onCancelAction: () async { onCancelAction: () {
_sendButtonState = ButtonState.enabled; _sendButtonState = ButtonState.enabled;
await Future.delayed( _closeComposerAction(closeOverlays: true);
const Duration(milliseconds: 100),
_closeComposerAction
);
}, },
icon: SvgPicture.asset( icon: SvgPicture.asset(
imagePaths.icQuotasWarning, imagePaths.icQuotasWarning,
@@ -1187,14 +1190,12 @@ class ComposerController extends BaseController with DragDropFileMixin {
failure: resultState, failure: resultState,
onConfirmAction: () { onConfirmAction: () {
_saveToDraftButtonState = ButtonState.enabled; _saveToDraftButtonState = ButtonState.enabled;
popBack();
_autoFocusFieldWhenLauncher(); _autoFocusFieldWhenLauncher();
}, },
onCancelAction: () async { onCancelAction: () {
_saveToDraftButtonState = ButtonState.enabled; _saveToDraftButtonState = ButtonState.enabled;
await Future.delayed( _closeComposerAction(closeOverlays: true);
const Duration(milliseconds: 100),
_closeComposerAction
);
} }
); );
} else { } else {
@@ -1320,11 +1321,14 @@ class ComposerController extends BaseController with DragDropFileMixin {
FocusScope.of(context).unfocus(); FocusScope.of(context).unfocus();
} }
void _closeComposerAction({dynamic result}) { void _closeComposerAction({dynamic result, bool closeOverlays = false}) {
if (PlatformInfo.isWeb) { if (PlatformInfo.isWeb) {
if (closeOverlays) {
popBack();
}
mailboxDashBoardController.closeComposerOverlay(result: result); mailboxDashBoardController.closeComposerOverlay(result: result);
} else { } else {
popBack(result: result); popBack(result: result, closeOverlays: closeOverlays);
} }
} }
@@ -1916,16 +1920,11 @@ class ComposerController extends BaseController with DragDropFileMixin {
cancelTitle: AppLocalizations.of(context).discardChanges, cancelTitle: AppLocalizations.of(context).discardChanges,
alignCenter: true, alignCenter: true,
outsideDismissible: false, outsideDismissible: false,
onConfirmAction: () async => await Future.delayed( autoPerformPopBack: false,
const Duration(milliseconds: 100), onConfirmAction: () => _handleSaveMessageToDraft(context),
() => _handleSaveMessageToDraft(context) onCancelAction: () {
),
onCancelAction: () async {
_closeComposerButtonState = ButtonState.enabled; _closeComposerButtonState = ButtonState.enabled;
await Future.delayed( _closeComposerAction(closeOverlays: true);
const Duration(milliseconds: 100),
_closeComposerAction
);
}, },
onCloseButtonAction: () { onCloseButtonAction: () {
_closeComposerButtonState = ButtonState.enabled; _closeComposerButtonState = ButtonState.enabled;
@@ -2010,10 +2009,12 @@ class ComposerController extends BaseController with DragDropFileMixin {
) { ) {
log('ComposerController::_handleSaveMessageToDraft: SESSION or ACCOUNT_ID or ARGUMENTS is NULL'); log('ComposerController::_handleSaveMessageToDraft: SESSION or ACCOUNT_ID or ARGUMENTS is NULL');
_closeComposerButtonState = ButtonState.enabled; _closeComposerButtonState = ButtonState.enabled;
_closeComposerAction(); _closeComposerAction(closeOverlays: true);
return; return;
} }
popBack();
final emailContent = await _getContentInEditor(); final emailContent = await _getContentInEditor();
final draftEmailId = _getDraftEmailId(); final draftEmailId = _getDraftEmailId();
log('ComposerController::_handleSaveMessageToDraft: draftEmailId = $draftEmailId'); log('ComposerController::_handleSaveMessageToDraft: draftEmailId = $draftEmailId');
@@ -2118,16 +2119,15 @@ class ComposerController extends BaseController with DragDropFileMixin {
cancelTitle: AppLocalizations.of(context).closeAnyway, cancelTitle: AppLocalizations.of(context).closeAnyway,
alignCenter: true, alignCenter: true,
outsideDismissible: false, outsideDismissible: false,
autoPerformPopBack: false,
onConfirmAction: onConfirmAction ?? () { onConfirmAction: onConfirmAction ?? () {
_closeComposerButtonState = ButtonState.enabled; _closeComposerButtonState = ButtonState.enabled;
popBack();
_autoFocusFieldWhenLauncher(); _autoFocusFieldWhenLauncher();
}, },
onCancelAction: onCancelAction ?? () async { onCancelAction: onCancelAction ?? () {
_closeComposerButtonState = ButtonState.enabled; _closeComposerButtonState = ButtonState.enabled;
await Future.delayed( _closeComposerAction(closeOverlays: true);
const Duration(milliseconds: 100),
_closeComposerAction
);
}, },
icon: SvgPicture.asset( icon: SvgPicture.asset(
imagePaths.icQuotasWarning, imagePaths.icQuotasWarning,
+2 -2
View File
@@ -18,8 +18,8 @@ Future<dynamic> pushAndPopAll(String routeName, {dynamic arguments}) async {
return Get.offAllNamed(routeName, arguments: arguments); return Get.offAllNamed(routeName, arguments: arguments);
} }
void popBack({dynamic result}) { void popBack({dynamic result, bool closeOverlays = false}) {
Get.back(result: result); Get.back(closeOverlays: closeOverlays, result: result);
} }
bool canBack(BuildContext context) { bool canBack(BuildContext context) {