TF-1877 Fix error TextEditingController was used after being disposed on some screen
(cherry picked from commit 50e4c6ec55eea21a45a5a8dd31cd239245248df3)
This commit is contained in:
@@ -22,8 +22,8 @@ import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
||||
|
||||
class ContactController extends BaseController {
|
||||
|
||||
TextEditingController? textInputSearchController;
|
||||
FocusNode? textInputSearchFocus;
|
||||
final TextEditingController textInputSearchController = TextEditingController();
|
||||
final FocusNode textInputSearchFocus = FocusNode();
|
||||
ContactSuggestionSource _contactSuggestionSource = ContactSuggestionSource.tMailContact;
|
||||
|
||||
final searchQuery = SearchQuery.initial().obs;
|
||||
@@ -32,9 +32,9 @@ class ContactController extends BaseController {
|
||||
GetAutoCompleteWithDeviceContactInteractor? _getAutoCompleteWithDeviceContactInteractor;
|
||||
GetAutoCompleteInteractor? _getAutoCompleteInteractor;
|
||||
|
||||
late Debouncer<String> _deBouncerTime;
|
||||
late AccountId _accountId;
|
||||
late Session _session;
|
||||
final Debouncer<String> _deBouncerTime = Debouncer<String>(const Duration(milliseconds: 500), initialValue: '');
|
||||
AccountId? _accountId;
|
||||
Session? _session;
|
||||
|
||||
ContactArguments? arguments;
|
||||
EmailAddress? contactSelected;
|
||||
@@ -44,14 +44,19 @@ class ContactController extends BaseController {
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
textInputSearchController = TextEditingController();
|
||||
textInputSearchFocus = FocusNode();
|
||||
_initializeDebounceTimeTextSearchChange();
|
||||
log('ContactController::onInit():arguments: ${Get.arguments}');
|
||||
arguments = Get.arguments;
|
||||
_deBouncerTime.values.listen((value) {
|
||||
searchQuery.value = SearchQuery(value);
|
||||
_searchContactByNameOrEmail(searchQuery.value.value);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() async {
|
||||
textInputSearchFocus?.requestFocus();
|
||||
super.onReady();
|
||||
log('ContactController::onReady():');
|
||||
textInputSearchFocus.requestFocus();
|
||||
if (arguments != null) {
|
||||
_accountId = arguments!.accountId;
|
||||
_session = arguments!.session;
|
||||
@@ -68,25 +73,17 @@ class ContactController extends BaseController {
|
||||
const Duration(milliseconds: 500),
|
||||
() => _checkContactPermission());
|
||||
}
|
||||
super.onReady();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
_disposeWidget();
|
||||
log('ContactController::onClose():');
|
||||
textInputSearchFocus.dispose();
|
||||
textInputSearchController.dispose();
|
||||
_deBouncerTime.cancel();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
void _initializeDebounceTimeTextSearchChange() {
|
||||
_deBouncerTime = Debouncer<String>(
|
||||
const Duration(milliseconds: 500),
|
||||
initialValue: '');
|
||||
_deBouncerTime.values.listen((value) async {
|
||||
searchQuery.value = SearchQuery(value);
|
||||
_searchContactByNameOrEmail(searchQuery.value.value);
|
||||
});
|
||||
}
|
||||
|
||||
void onTextSearchChange(String text) {
|
||||
_deBouncerTime.value = text;
|
||||
}
|
||||
@@ -96,9 +93,9 @@ class ContactController extends BaseController {
|
||||
}
|
||||
|
||||
void clearAllTextInputSearchForm() {
|
||||
textInputSearchController?.clear();
|
||||
textInputSearchController.clear();
|
||||
searchQuery.value = SearchQuery.initial();
|
||||
textInputSearchFocus?.requestFocus();
|
||||
textInputSearchFocus.requestFocus();
|
||||
}
|
||||
|
||||
void _checkContactPermission() async {
|
||||
@@ -167,32 +164,14 @@ class ContactController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
void _disposeWidget() {
|
||||
textInputSearchFocus?.dispose();
|
||||
textInputSearchFocus = null;
|
||||
textInputSearchController?.dispose();
|
||||
textInputSearchController = null;
|
||||
_deBouncerTime.cancel();
|
||||
}
|
||||
|
||||
void selectContact(BuildContext context, EmailAddress emailAddress) {
|
||||
KeyboardUtils.hideKeyboard(context);
|
||||
|
||||
if (PlatformInfo.isWeb) {
|
||||
onSelectedContactCallback?.call(emailAddress);
|
||||
} else {
|
||||
popBack(result: emailAddress);
|
||||
}
|
||||
popBack(result: emailAddress);
|
||||
}
|
||||
|
||||
void closeContactView(BuildContext context) {
|
||||
clearAllTextInputSearchForm();
|
||||
KeyboardUtils.hideKeyboard(context);
|
||||
|
||||
if (PlatformInfo.isWeb) {
|
||||
onDismissContactView?.call();
|
||||
} else {
|
||||
popBack();
|
||||
}
|
||||
popBack();
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import 'package:get/get.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/widgets/suggestion_email_address.dart';
|
||||
import 'package:tmail_ui_user/features/contact/presentation/contact_controller.dart';
|
||||
import 'package:tmail_ui_user/features/contact/presentation/model/contact_arguments.dart';
|
||||
import 'package:tmail_ui_user/features/contact/presentation/utils/contact_utils.dart';
|
||||
import 'package:tmail_ui_user/features/contact/presentation/widgets/app_bar_contact_widget.dart';
|
||||
import 'package:tmail_ui_user/features/contact/presentation/widgets/contact_suggestion_box_item.dart';
|
||||
@@ -20,23 +19,7 @@ class ContactView extends GetWidget<ContactController> {
|
||||
final _responsiveUtils = Get.find<ResponsiveUtils>();
|
||||
final _imagePaths = Get.find<ImagePaths>();
|
||||
|
||||
@override
|
||||
final controller = Get.find<ContactController>();
|
||||
|
||||
ContactView({Key? key}) : super(key: key) {
|
||||
controller.arguments = Get.arguments;
|
||||
}
|
||||
|
||||
ContactView.fromArguments(
|
||||
ContactArguments arguments, {
|
||||
Key? key,
|
||||
SelectedContactCallbackAction? onSelectedContactCallback,
|
||||
VoidCallback? onDismissCallback
|
||||
}) : super(key: key) {
|
||||
controller.arguments = arguments;
|
||||
controller.onSelectedContactCallback = onSelectedContactCallback;
|
||||
controller.onDismissContactView = onDismissCallback;
|
||||
}
|
||||
ContactView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -82,7 +65,7 @@ class ContactView extends GetWidget<ContactController> {
|
||||
imagePaths: _imagePaths,
|
||||
searchQuery: controller.searchQuery.value,
|
||||
searchFocusNode: controller.textInputSearchFocus,
|
||||
searchInputController :controller.textInputSearchController,
|
||||
searchInputController: controller.textInputSearchController,
|
||||
hasBackButton: false,
|
||||
hasSearchButton: true,
|
||||
padding: EdgeInsets.zero,
|
||||
|
||||
Reference in New Issue
Block a user