Skip to content

Instantly share code, notes, and snippets.

@FlutterWiz
Created June 18, 2022 12:21
Show Gist options
  • Save FlutterWiz/3f90d2025e3376ec60b0dbc28197c679 to your computer and use it in GitHub Desktop.
Save FlutterWiz/3f90d2025e3376ec60b0dbc28197c679 to your computer and use it in GitHub Desktop.
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