Created
June 18, 2022 12:21
-
-
Save FlutterWiz/3f90d2025e3376ec60b0dbc28197c679 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SearchNotifier extends StateNotifier<SearchState> { | |
SearchNotifier() : super(SearchState.empty()); | |
void mapEventsToState(SearchEvent event) { | |
event.map( | |
searchedTextChanged: (searchedTextChangedEvent) { | |
final characterList = [...state.characterList]; | |
final searchedCharacterList = characterList | |
.where((characterModel) => characterModel.characterName | |
.toLowerCase() | |
.contains(searchedTextChangedEvent.text.toLowerCase().trimLeft())) | |
.toList(); | |
state = state.copyWith(characterList: searchedCharacterList); | |
}, | |
updateListItems: (updateListItemsEvent) { | |
state = state.copyWith( | |
characterList: updateListItemsEvent.characterModelList, | |
); | |
}, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment