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( Stream<KanjiState> mapEventToState(
KanjiEvent event, KanjiEvent event,
) async* { ) async* {
yield KanjiSearchLoading();
if (event is GetKanji) { if (event is GetKanji) {
yield KanjiSearchLoading();
try { try {
final _kanji = await fetchKanji(event.kanjiSearchString); final _kanji = await fetchKanji(event.kanjiSearchString);
yield KanjiSearchFinished(_kanji); yield KanjiSearchFinished(_kanji);
} on Exception { } on Exception {
yield KanjiSearchError('Something went wrong'); yield KanjiSearchError('Something went wrong');
} }
} else if (event is ReturnToInitialState) {
yield KanjiSearchInitial();
} }
} }
} }

View File

@ -7,3 +7,7 @@ class GetKanji extends KanjiEvent {
GetKanji(this.kanjiSearchString); GetKanji(this.kanjiSearchString);
} }
class ReturnToInitialState extends KanjiEvent {
ReturnToInitialState();
}