AppBarCreateBloc constructor
AppBarCreateBloc(
- String appId,
- AppBarModel initialiseWithAppBar
Implementation
AppBarCreateBloc(
this.appId,
AppBarModel initialiseWithAppBar,
) : appBarModel = deepCopy(appId, initialiseWithAppBar),
super(AppBarCreateUninitialised()) {
on<AppBarCreateEventValidateEvent>((event, emit) {
// the updates happen on a (deep) copy
emit(AppBarCreateValidated(deepCopy(appId, event.appBarModel)));
});
on<AppBarCreateEventApplyChanges>((event, emit) async {
var theState = state as AppBarCreateInitialised;
appBarModel.iconMenu = theState.appBarModel.iconMenu;
if (event.save) {
var appBar = await appBarRepository(appId: appBarModel.appId)!
.get(theState.appBarModel.documentID);
if (appBar == null) {
await appBarRepository(appId: appBarModel.appId)!
.add(theState.appBarModel);
} else {
await appBarRepository(appId: appBarModel.appId)!
.update(theState.appBarModel);
}
var menuDef = await menuDefRepository(appId: appBarModel.appId)!
.get(theState.appBarModel.iconMenu!.documentID);
if (menuDef == null) {
await menuDefRepository(appId: appBarModel.appId)!
.add(theState.appBarModel.iconMenu!);
} else {
await menuDefRepository(appId: appBarModel.appId)!
.update(theState.appBarModel.iconMenu!);
}
}
});
}