live local search
todos improve local search
This commit is contained in:
parent
4ade7f1682
commit
a0ed894016
9 changed files with 151 additions and 42 deletions
|
@ -7,12 +7,12 @@ import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
|||
import '/features/core/abstracts/base_view_model.dart';
|
||||
import '/features/core/services/logging_service.dart';
|
||||
import '/features/core/services/navigation_service.dart';
|
||||
import '/features/home/data/models/image_model.dart';
|
||||
import '/features/home/services/image_cache_manager_service.dart';
|
||||
import '/features/home/services/images_service.dart';
|
||||
import '/features/home/views/image_carousel/image_carousel_view.dart';
|
||||
import '/locator.dart';
|
||||
import '../../data/enums/search_option.dart';
|
||||
import '../../data/models/image_model.dart';
|
||||
import '../../services/image_cache_manager_service.dart';
|
||||
import '../../services/images_service.dart';
|
||||
import '../image_carousel/image_carousel_view.dart';
|
||||
|
||||
class GalleryViewModel extends BaseViewModel {
|
||||
GalleryViewModel({
|
||||
|
@ -54,17 +54,20 @@ class GalleryViewModel extends BaseViewModel {
|
|||
// If empty-string (from backspacing) -> reset state.
|
||||
if (searchTerm.isEmpty) {
|
||||
_imageSearchResultsNotifier.value = [];
|
||||
_loggingService.info('Clearing results on search string removal');
|
||||
return;
|
||||
}
|
||||
|
||||
// Detached call to prevent UI blocking
|
||||
unawaited(_imagesService
|
||||
.searchImages(
|
||||
imageNamePart: searchTerm,
|
||||
searchOption: searchOptionListenable.value,
|
||||
)
|
||||
.then(
|
||||
(final fetchedImageModels) => _imageSearchResultsNotifier.value = fetchedImageModels));
|
||||
unawaited(
|
||||
_imagesService
|
||||
.searchImages(
|
||||
imageNamePart: searchTerm,
|
||||
searchOption: searchOptionListenable.value,
|
||||
)
|
||||
.then(
|
||||
(final fetchedImageModels) => _imageSearchResultsNotifier.value = fetchedImageModels),
|
||||
);
|
||||
|
||||
// Force-update to trigger listening to `lastQueryResultDone()`.
|
||||
_imageSearchResultsNotifier.notifyListeners();
|
||||
|
@ -72,14 +75,25 @@ class GalleryViewModel extends BaseViewModel {
|
|||
|
||||
void searchPressed() {
|
||||
// If transitioning from 'Searching', clear previous results immediately
|
||||
if (_isSearchingNotifier.value) _imageSearchResultsNotifier.value = [];
|
||||
if (_isSearchingNotifier.value) {
|
||||
_imageSearchResultsNotifier.value = [];
|
||||
_loggingService.info('Clearing of results on view mode change');
|
||||
}
|
||||
|
||||
_isSearchingNotifier.value = !_isSearchingNotifier.value;
|
||||
}
|
||||
|
||||
Future<void> get lastQueryResultDone => _imagesService.lastQueryIsCompleted;
|
||||
|
||||
void onSearchOptionChanged(SearchOption? option) => _searchOptionNotifier.value = option!;
|
||||
void onSearchOptionChanged(SearchOption? option) {
|
||||
_searchOptionNotifier.value = option!;
|
||||
_loggingService.info('Switched over to $option search');
|
||||
|
||||
_imageSearchResultsNotifier.value = [];
|
||||
_loggingService.info('Cleared resultsw from view');
|
||||
|
||||
//todo(mehul): Either redo search or force user to type in by clearing field
|
||||
}
|
||||
|
||||
void onPromptPressed() => _isDisplayingPressingPrompt.value = false;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue