PresentationFormBloc(- String? appId,
- {FormAction? formAction}
)
Implementation
PresentationFormBloc(this.appId, {this.formAction})
: super(PresentationFormUninitialized()) {
on<InitialiseNewPresentationFormEvent>((event, emit) {
PresentationFormLoaded loaded = PresentationFormLoaded(
value: PresentationModel(
documentID: "",
appId: "",
description: "",
bodyComponents: [],
imageWidth: 0.0,
));
emit(loaded);
});
on<InitialisePresentationFormEvent>((event, emit) async {
// Need to re-retrieve the document from the repository so that I get all associated types
PresentationFormLoaded loaded = PresentationFormLoaded(
value: await presentationRepository(appId: appId)!
.get(event.value!.documentID));
emit(loaded);
});
on<InitialisePresentationFormNoLoadEvent>((event, emit) async {
PresentationFormLoaded loaded =
PresentationFormLoaded(value: event.value);
emit(loaded);
});
PresentationModel? newValue;
on<ChangedPresentationDocumentID>((event, emit) async {
if (state is PresentationFormInitialized) {
final currentState = state as PresentationFormInitialized;
newValue = currentState.value!.copyWith(documentID: event.value);
if (formAction == FormAction.addAction) {
emit(await _isDocumentIDValid(event.value, newValue!));
} else {
emit(SubmittablePresentationForm(value: newValue));
}
}
});
on<ChangedPresentationDescription>((event, emit) async {
if (state is PresentationFormInitialized) {
final currentState = state as PresentationFormInitialized;
newValue = currentState.value!.copyWith(description: event.value);
emit(SubmittablePresentationForm(value: newValue));
}
});
on<ChangedPresentationBodyComponents>((event, emit) async {
if (state is PresentationFormInitialized) {
final currentState = state as PresentationFormInitialized;
newValue = currentState.value!.copyWith(bodyComponents: event.value);
emit(SubmittablePresentationForm(value: newValue));
}
});
on<ChangedPresentationImage>((event, emit) async {
if (state is PresentationFormInitialized) {
final currentState = state as PresentationFormInitialized;
if (event.value != null) {
newValue = currentState.value!.copyWith(
image: await platformMediumRepository(appId: appId)!
.get(event.value));
}
emit(SubmittablePresentationForm(value: newValue));
}
});
on<ChangedPresentationImagePositionRelative>((event, emit) async {
if (state is PresentationFormInitialized) {
final currentState = state as PresentationFormInitialized;
newValue =
currentState.value!.copyWith(imagePositionRelative: event.value);
emit(SubmittablePresentationForm(value: newValue));
}
});
on<ChangedPresentationImageAlignment>((event, emit) async {
if (state is PresentationFormInitialized) {
final currentState = state as PresentationFormInitialized;
newValue = currentState.value!.copyWith(imageAlignment: event.value);
emit(SubmittablePresentationForm(value: newValue));
}
});
on<ChangedPresentationImageWidth>((event, emit) async {
if (state is PresentationFormInitialized) {
final currentState = state as PresentationFormInitialized;
if (isDouble(event.value!)) {
newValue = currentState.value!
.copyWith(imageWidth: double.parse(event.value!));
emit(SubmittablePresentationForm(value: newValue));
} else {
newValue = currentState.value!.copyWith(imageWidth: 0.0);
emit(ImageWidthPresentationFormError(
message: "Value should be a number or decimal number",
value: newValue));
}
}
});
on<ChangedPresentationConditions>((event, emit) async {
if (state is PresentationFormInitialized) {
final currentState = state as PresentationFormInitialized;
newValue = currentState.value!.copyWith(conditions: event.value);
emit(SubmittablePresentationForm(value: newValue));
}
});
}