Add event for returning to initial state
This commit is contained in:
parent
8ee5dc7f58
commit
d126f54500
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,3 +7,7 @@ class GetKanji extends KanjiEvent {
|
||||||
|
|
||||||
GetKanji(this.kanjiSearchString);
|
GetKanji(this.kanjiSearchString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ReturnToInitialState extends KanjiEvent {
|
||||||
|
ReturnToInitialState();
|
||||||
|
}
|
Loading…
Reference in New Issue