TF-452 Fix search boxes should be collapsed automatically when search inputs lost focus
This commit is contained in:
@@ -117,6 +117,7 @@ class MailboxController extends BaseMailboxController {
|
||||
@override
|
||||
void onInit() {
|
||||
_initWorker();
|
||||
_registerSearchFocusListener();
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
@@ -234,6 +235,17 @@ class MailboxController extends BaseMailboxController {
|
||||
});
|
||||
}
|
||||
|
||||
void _registerSearchFocusListener() {
|
||||
searchFocus.addListener(() {
|
||||
final hasFocus = searchFocus.hasFocus;
|
||||
final query = searchQuery.value.value;
|
||||
log('MailboxController::_registerSearchFocusListener(): hasFocus: $hasFocus | query: $query');
|
||||
if (!hasFocus && query.isEmpty) {
|
||||
disableSearch();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _clearWorker() {
|
||||
accountIdWorker.call();
|
||||
viewStateWorker.call();
|
||||
@@ -396,13 +408,13 @@ class MailboxController extends BaseMailboxController {
|
||||
searchState.value = searchState.value.enableSearchState();
|
||||
}
|
||||
|
||||
void disableSearch(BuildContext context) {
|
||||
void disableSearch() {
|
||||
_cancelSelectMailbox();
|
||||
listMailboxSearched.clear();
|
||||
searchState.value = searchState.value.disableSearchState();
|
||||
searchQuery.value = SearchQuery.initial();
|
||||
searchInputController.clear();
|
||||
FocusScope.of(context).unfocus();
|
||||
searchFocus.unfocus();
|
||||
}
|
||||
|
||||
void clearSearchText() {
|
||||
|
||||
@@ -333,7 +333,7 @@ class MailboxView extends GetWidget<MailboxController> {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(left: _responsiveUtils.isLandscapeMobile(context) ? 0 : 5),
|
||||
child: buildIconWeb(
|
||||
onTap: () => controller.disableSearch(context),
|
||||
onTap: () => controller.disableSearch(),
|
||||
icon: SvgPicture.asset(_imagePaths.icBack, color: AppColor.colorTextButton),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ class MailboxView extends GetWidget<MailboxController> with AppLoaderMixin, Popu
|
||||
minSize: 40,
|
||||
splashRadius: 15,
|
||||
icon: SvgPicture.asset(_imagePaths.icBack, color: AppColor.colorTextButton),
|
||||
onTap: () => controller.disableSearch(context)),
|
||||
onTap: () => controller.disableSearch()),
|
||||
Expanded(child: (SearchAppBarWidget(
|
||||
_imagePaths,
|
||||
controller.searchQuery.value,
|
||||
|
||||
@@ -125,6 +125,7 @@ class MailboxDashBoardController extends ReloadableController {
|
||||
void onInit() {
|
||||
_registerNetworkConnectivityState();
|
||||
_registerPendingEmailAddress();
|
||||
_registerSearchFocusListener();
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
@@ -224,6 +225,17 @@ class MailboxDashBoardController extends ReloadableController {
|
||||
});
|
||||
}
|
||||
|
||||
void _registerSearchFocusListener() {
|
||||
searchFocus.addListener(() {
|
||||
final hasFocus = searchFocus.hasFocus;
|
||||
final query = searchQuery?.value;
|
||||
log('MailboxDashBoardController::_registerSearchFocusListener(): hasFocus: $hasFocus | query: $query');
|
||||
if (!hasFocus && (query == null || query.isEmpty)) {
|
||||
disableSearch();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _getUserProfile() async {
|
||||
userProfile.value = sessionCurrent != null ? UserProfile(sessionCurrent!.username.value) : null;
|
||||
}
|
||||
@@ -300,7 +312,7 @@ class MailboxDashBoardController extends ReloadableController {
|
||||
searchInputController.clear();
|
||||
listFilterQuickSearch.clear();
|
||||
emailReceiveTimeType.value = null;
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
searchFocus.unfocus();
|
||||
}
|
||||
|
||||
void clearTextSearch() {
|
||||
@@ -309,6 +321,10 @@ class MailboxDashBoardController extends ReloadableController {
|
||||
searchFocus.requestFocus();
|
||||
}
|
||||
|
||||
void onChangeTextSearch(String value) {
|
||||
searchQuery = SearchQuery(value);
|
||||
}
|
||||
|
||||
void updateTextSearch(String value) {
|
||||
searchInputController.text = value;
|
||||
}
|
||||
|
||||
@@ -420,6 +420,10 @@ class MailboxDashBoardView extends BaseMailboxDashBoardView {
|
||||
}
|
||||
controller.searchEmail(context, keyword);
|
||||
},
|
||||
onChanged: (query) {
|
||||
log('MailboxDashBoardView::_buildSearchForm(): onChanged: $query');
|
||||
controller.onChangeTextSearch(query);
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
border: InputBorder.none,
|
||||
focusedBorder: InputBorder.none,
|
||||
|
||||
Reference in New Issue
Block a user