From ba2eb2516db5340c178f3975dc9dfbf5d19aa975 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Thu, 18 Aug 2022 10:39:39 +0530 Subject: [PATCH] only show resutls if query is not empty --- lib/ui/viewer/search/search_widget.dart | 41 +++++++++++++------------ 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/lib/ui/viewer/search/search_widget.dart b/lib/ui/viewer/search/search_widget.dart index beec4830b..747de423a 100644 --- a/lib/ui/viewer/search/search_widget.dart +++ b/lib/ui/viewer/search/search_widget.dart @@ -142,27 +142,30 @@ class _SearchWidgetState extends State { Future> getSearchResultsForQuery(String query) async { final List allResults = []; - final queryAsIntForYear = int.tryParse(query); - if (_isYearValid(queryAsIntForYear)) { - final yearResult = - await _searchService.getYearSearchResults(queryAsIntForYear); - allResults.add(yearResult); //only one year will be returned + if (query.isNotEmpty) { + final queryAsIntForYear = int.tryParse(query); + if (_isYearValid(queryAsIntForYear)) { + final yearResult = + await _searchService.getYearSearchResults(queryAsIntForYear); + allResults.add(yearResult); //only one year will be returned + } + + final holidayResults = + await _searchService.getHolidaySearchResults(query); + allResults.addAll(holidayResults); + + final collectionResults = + await _searchService.getCollectionSearchResults(query); + allResults.addAll(collectionResults); + + final locationResults = + await _searchService.getLocationSearchResults(query); + allResults.addAll(locationResults); + + final monthResults = await _searchService.getMonthSearchResults(query); + allResults.addAll(monthResults); } - final holidayResults = await _searchService.getHolidaySearchResults(query); - allResults.addAll(holidayResults); - - final collectionResults = - await _searchService.getCollectionSearchResults(query); - allResults.addAll(collectionResults); - - final locationResults = - await _searchService.getLocationSearchResults(query); - allResults.addAll(locationResults); - - final monthResults = await _searchService.getMonthSearchResults(query); - allResults.addAll(monthResults); - return allResults; }