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