TutorialEntryFormBloc(- String? appId
)
Implementation
TutorialEntryFormBloc(
this.appId,
) : super(TutorialEntryFormUninitialized()) {
on<InitialiseNewTutorialEntryFormEvent>((event, emit) {
TutorialEntryFormLoaded loaded = TutorialEntryFormLoaded(
value: TutorialEntryModel(
documentID: "IDENTIFIED",
description: "",
code: "",
));
emit(loaded);
});
on<InitialiseTutorialEntryFormEvent>((event, emit) async {
TutorialEntryFormLoaded loaded =
TutorialEntryFormLoaded(value: event.value);
emit(loaded);
});
on<InitialiseTutorialEntryFormNoLoadEvent>((event, emit) async {
TutorialEntryFormLoaded loaded =
TutorialEntryFormLoaded(value: event.value);
emit(loaded);
});
TutorialEntryModel? newValue;
on<ChangedTutorialEntryDescription>((event, emit) async {
if (state is TutorialEntryFormInitialized) {
final currentState = state as TutorialEntryFormInitialized;
newValue = currentState.value!.copyWith(description: event.value);
emit(SubmittableTutorialEntryForm(value: newValue));
}
});
on<ChangedTutorialEntryImage>((event, emit) async {
if (state is TutorialEntryFormInitialized) {
final currentState = state as TutorialEntryFormInitialized;
if (event.value != null) {
newValue = currentState.value!.copyWith(
image: await platformMediumRepository(appId: appId)!
.get(event.value));
}
emit(SubmittableTutorialEntryForm(value: newValue));
}
});
on<ChangedTutorialEntryCode>((event, emit) async {
if (state is TutorialEntryFormInitialized) {
final currentState = state as TutorialEntryFormInitialized;
newValue = currentState.value!.copyWith(code: event.value);
emit(SubmittableTutorialEntryForm(value: newValue));
}
});
}