DialogCreateBloc constructor
DialogCreateBloc(
- String appId,
- DialogModel initialiseWithDialog
Implementation
DialogCreateBloc(this.appId, DialogModel initialiseWithDialog)
: dialogModel = deepCopy(initialiseWithDialog),
super(DialogCreateUninitialised()) {
on<DialogCreateEventValidateEvent>((event, emit) {
// convention is that the ID of the appBar, drawers and home menu are the same ID as that of the app
//var homeMenuId = homeMenuID(appId);
event.dialogModel.conditions ??= StorageConditionsModel(
privilegeLevelRequired:
PrivilegeLevelRequiredSimple.noPrivilegeRequiredSimple);
// the updates happen on a (deep) copy
emit(DialogCreateValidated(deepCopy(event.dialogModel)));
});
on<DialogCreateEventApplyChanges>((event, emit) async {
var theState = state as DialogCreateInitialised;
var dialog = await dialogRepository(appId: theState.dialogModel.appId)!
.get(theState.dialogModel.documentID);
if (dialog == null) {
await dialogRepository(appId: theState.dialogModel.appId)!
.add(theState.dialogModel);
} else {
await dialogRepository(appId: theState.dialogModel.appId)!
.update(theState.dialogModel);
}
});
}