TF-1877 Fix error TextEditingController was used after being disposed on some screen
(cherry picked from commit 50e4c6ec55eea21a45a5a8dd31cd239245248df3)
This commit is contained in:
@@ -1,33 +1,12 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tmail_ui_user/features/base/base_bindings.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_creator/domain/usecases/verify_name_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_creator/presentation/mailbox_creator_controller.dart';
|
||||
|
||||
class MailboxCreatorBindings extends BaseBindings {
|
||||
class MailboxCreatorBindings extends Bindings {
|
||||
|
||||
@override
|
||||
void bindingsController() {
|
||||
void dependencies() {
|
||||
Get.lazyPut(() => VerifyNameInteractor());
|
||||
Get.lazyPut(() => MailboxCreatorController(Get.find<VerifyNameInteractor>()));
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsDataSource() {}
|
||||
|
||||
@override
|
||||
void bindingsDataSourceImpl() {}
|
||||
|
||||
@override
|
||||
void bindingsInteractor() {
|
||||
Get.lazyPut(() => VerifyNameInteractor());
|
||||
}
|
||||
|
||||
@override
|
||||
void bindingsRepository() {}
|
||||
|
||||
@override
|
||||
void bindingsRepositoryImpl() {}
|
||||
|
||||
void dispose() {
|
||||
Get.delete<MailboxCreatorController>();
|
||||
}
|
||||
}
|
||||
@@ -19,10 +19,9 @@ import 'package:tmail_ui_user/features/mailbox_creator/presentation/extensions/v
|
||||
import 'package:tmail_ui_user/features/mailbox_creator/presentation/model/mailbox_creator_arguments.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_creator/presentation/model/new_mailbox_arguments.dart';
|
||||
import 'package:tmail_ui_user/main/routes/app_routes.dart';
|
||||
import 'package:tmail_ui_user/main/routes/dialog_router.dart';
|
||||
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
||||
|
||||
typedef OnCreatedMailboxCallback = Function(NewMailboxArguments? arguments);
|
||||
|
||||
class MailboxCreatorController extends BaseController {
|
||||
|
||||
final VerifyNameInteractor _verifyNameInteractor;
|
||||
@@ -31,8 +30,8 @@ class MailboxCreatorController extends BaseController {
|
||||
final newNameMailbox = Rxn<String>();
|
||||
bool _createdMailbox = false;
|
||||
|
||||
FocusNode? nameInputFocusNode;
|
||||
TextEditingController? nameInputController;
|
||||
final FocusNode nameInputFocusNode = FocusNode();
|
||||
final TextEditingController nameInputController = TextEditingController();
|
||||
|
||||
MailboxCreatorArguments? arguments;
|
||||
AccountId? accountId;
|
||||
@@ -40,8 +39,6 @@ class MailboxCreatorController extends BaseController {
|
||||
MailboxTree? defaultMailboxTree;
|
||||
MailboxTree? personalMailboxTree;
|
||||
MailboxTree? teamMailboxesTre;
|
||||
OnCreatedMailboxCallback? onCreatedMailboxCallback;
|
||||
VoidCallback? onDismissMailboxCreator;
|
||||
|
||||
List<String> listMailboxNameAsStringExist = <String>[];
|
||||
|
||||
@@ -52,13 +49,14 @@ class MailboxCreatorController extends BaseController {
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
nameInputFocusNode = FocusNode();
|
||||
nameInputController = TextEditingController();
|
||||
log('MailboxCreatorController::onInit():arguments: ${Get.arguments}');
|
||||
arguments = Get.arguments;
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
super.onReady();
|
||||
log('MailboxCreatorController::onReady():');
|
||||
if (arguments != null) {
|
||||
personalMailboxTree = arguments!.personalMailboxTree;
|
||||
defaultMailboxTree = arguments!.defaultMailboxTree;
|
||||
@@ -71,7 +69,9 @@ class MailboxCreatorController extends BaseController {
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
_disposeWidget();
|
||||
log('MailboxCreatorController::onClose():');
|
||||
nameInputFocusNode.dispose();
|
||||
nameInputController.dispose();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ class MailboxCreatorController extends BaseController {
|
||||
|
||||
String? getErrorInputNameString(BuildContext context) {
|
||||
final nameMailbox = newNameMailbox.value;
|
||||
final canCheckNameString = _createdMailbox && nameInputFocusNode?.hasFocus == false;
|
||||
final canCheckNameString = _createdMailbox && nameInputFocusNode.hasFocus == false;
|
||||
|
||||
return _verifyNameInteractor.execute(
|
||||
nameMailbox,
|
||||
@@ -138,47 +138,26 @@ class MailboxCreatorController extends BaseController {
|
||||
|
||||
if (accountId != null) {
|
||||
final arguments = DestinationPickerArguments(
|
||||
accountId!,
|
||||
MailboxActions.create,
|
||||
_session,
|
||||
mailboxIdSelected: selectedMailbox.value?.id);
|
||||
accountId!,
|
||||
MailboxActions.create,
|
||||
_session,
|
||||
mailboxIdSelected: selectedMailbox.value?.id);
|
||||
|
||||
if (PlatformInfo.isWeb) {
|
||||
showDialogDestinationPicker(
|
||||
context: context,
|
||||
arguments: arguments,
|
||||
onSelectedMailbox: (destinationMailbox) {
|
||||
final mailboxDestination = destinationMailbox == PresentationMailbox.unifiedMailbox
|
||||
? null
|
||||
: destinationMailbox;
|
||||
final destinationMailbox = PlatformInfo.isWeb
|
||||
? await DialogRouter.pushGeneralDialog(routeName: AppRoutes.destinationPicker, arguments: arguments)
|
||||
: await push(AppRoutes.destinationPicker, arguments: arguments);
|
||||
|
||||
selectedMailbox.value = mailboxDestination;
|
||||
_createListMailboxNameAsStringInMailboxLocation();
|
||||
});
|
||||
} else {
|
||||
final destinationMailbox = await push(
|
||||
AppRoutes.destinationPicker,
|
||||
arguments: arguments);
|
||||
if (destinationMailbox is PresentationMailbox) {
|
||||
final mailboxDestination = destinationMailbox == PresentationMailbox.unifiedMailbox
|
||||
? null
|
||||
: destinationMailbox;
|
||||
|
||||
if (destinationMailbox is PresentationMailbox) {
|
||||
final mailboxDestination = destinationMailbox == PresentationMailbox.unifiedMailbox
|
||||
? null
|
||||
: destinationMailbox;
|
||||
|
||||
selectedMailbox.value = mailboxDestination;
|
||||
_createListMailboxNameAsStringInMailboxLocation();
|
||||
}
|
||||
selectedMailbox.value = mailboxDestination;
|
||||
_createListMailboxNameAsStringInMailboxLocation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _disposeWidget() {
|
||||
nameInputFocusNode?.dispose();
|
||||
nameInputFocusNode = null;
|
||||
nameInputController?.dispose();
|
||||
nameInputController = null;
|
||||
}
|
||||
|
||||
void createNewMailbox(BuildContext context) {
|
||||
KeyboardUtils.hideKeyboard(context);
|
||||
|
||||
@@ -191,24 +170,14 @@ class MailboxCreatorController extends BaseController {
|
||||
|
||||
if (nameMailbox != null && nameMailbox.isNotEmpty && _createdMailbox) {
|
||||
final newMailboxArguments = NewMailboxArguments(
|
||||
MailboxName(nameMailbox),
|
||||
mailboxLocation: selectedMailbox.value);
|
||||
|
||||
if (PlatformInfo.isWeb) {
|
||||
onCreatedMailboxCallback?.call(newMailboxArguments);
|
||||
} else {
|
||||
popBack(result: newMailboxArguments);
|
||||
}
|
||||
MailboxName(nameMailbox),
|
||||
mailboxLocation: selectedMailbox.value);
|
||||
popBack(result: newMailboxArguments);
|
||||
}
|
||||
}
|
||||
|
||||
void closeMailboxCreator(BuildContext context) {
|
||||
KeyboardUtils.hideKeyboard(context);
|
||||
|
||||
if (PlatformInfo.isWeb) {
|
||||
onDismissMailboxCreator?.call();
|
||||
} else {
|
||||
popBack();
|
||||
}
|
||||
popBack();
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import 'package:core/presentation/resources/image_paths.dart';
|
||||
import 'package:core/presentation/utils/responsive_utils.dart';
|
||||
import 'package:core/presentation/utils/style_utils.dart';
|
||||
import 'package:core/presentation/views/text/text_field_builder.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:core/utils/direction_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -11,7 +12,6 @@ import 'package:get/get.dart';
|
||||
import 'package:pointer_interceptor/pointer_interceptor.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/extensions/presentation_mailbox_extension.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_creator/presentation/mailbox_creator_controller.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_creator/presentation/model/mailbox_creator_arguments.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_creator/presentation/widgets/app_bar_mailbox_creator_builder.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_creator/presentation/widgets/create_mailbox_name_input_decoration_builder.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
@@ -25,23 +25,11 @@ class MailboxCreatorView extends GetWidget<MailboxCreatorController> {
|
||||
@override
|
||||
final controller = Get.find<MailboxCreatorController>();
|
||||
|
||||
MailboxCreatorView({Key? key}) : super(key: key) {
|
||||
controller.arguments = Get.arguments;
|
||||
}
|
||||
|
||||
MailboxCreatorView.fromArguments(
|
||||
MailboxCreatorArguments arguments, {
|
||||
Key? key,
|
||||
OnCreatedMailboxCallback? onCreatedMailboxCallback,
|
||||
VoidCallback? onDismissCallback
|
||||
}) : super(key: key) {
|
||||
controller.arguments = arguments;
|
||||
controller.onCreatedMailboxCallback = onCreatedMailboxCallback;
|
||||
controller.onDismissMailboxCreator = onDismissCallback;
|
||||
}
|
||||
MailboxCreatorView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
log('MailboxCreatorView::build():');
|
||||
return PointerInterceptor(
|
||||
child: GestureDetector(
|
||||
onTap: () => controller.closeMailboxCreator(context),
|
||||
@@ -114,7 +102,6 @@ class MailboxCreatorView extends GetWidget<MailboxCreatorController> {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
child: Obx(() => TextFieldBuilder(
|
||||
key: const Key('create_mailbox_name_input'),
|
||||
onTextChange: controller.setNewNameMailbox,
|
||||
keyboardType: TextInputType.visiblePassword,
|
||||
cursorColor: AppColor.colorTextButton,
|
||||
|
||||
Reference in New Issue
Block a user