1
0
mirror of https://github.com/h7x4/Jisho-Study-Tool.git synced 2024-12-21 13:37:29 +01:00

Add event for returning to initial state

This commit is contained in:
Oystein Kristoffer Tveit 2020-07-14 00:09:54 +02:00
parent 8ee5dc7f58
commit d126f54500
2 changed files with 10 additions and 1 deletions

View File

@ -17,14 +17,19 @@ class KanjiBloc extends Bloc<KanjiEvent, KanjiState> {
Stream<KanjiState> mapEventToState(
KanjiEvent event,
) async* {
yield KanjiSearchLoading();
if (event is GetKanji) {
yield KanjiSearchLoading();
try {
final _kanji = await fetchKanji(event.kanjiSearchString);
yield KanjiSearchFinished(_kanji);
} on Exception {
yield KanjiSearchError('Something went wrong');
}
} else if (event is ReturnToInitialState) {
yield KanjiSearchInitial();
}
}
}

View File

@ -6,4 +6,8 @@ class GetKanji extends KanjiEvent {
final String kanjiSearchString;
GetKanji(this.kanjiSearchString);
}
class ReturnToInitialState extends KanjiEvent {
ReturnToInitialState();
}