BodyComponentsCreateBloc constructor
BodyComponentsCreateBloc(
- AppModel app,
- List<
BodyComponentModel> bodyComponentsModel
Implementation
BodyComponentsCreateBloc(
this.app,
this.bodyComponentsModel,
) : super(BodyComponentsCreateUninitialised()) {
on<BodyComponentsCreateInitialiseEvent>((event, emit) {
//var appId = app.documentID;
emit(BodyComponentsCreateInitialised(
bodyComponentModels: event.bodyComponentsModel,
pluginWithComponents: retrievePluginsWithComponents(),
));
});
on<BodyComponentsCreateDeleteMenuItem>((event, emit) {
emit(_newStateDeleteItem(event.bodyComponentModel));
apply();
});
on<BodyComponentsMoveItem>((event, emit) {
BodyComponentsCreateInitialised theState =
state as BodyComponentsCreateInitialised;
List<BodyComponentModel> bodyComponentModels =
List.of(theState.bodyComponentModels);
int positionToMove =
bodyComponentModels.indexOf(event.bodyComponentModel);
if (event.moveItemDirection == MoveItemDirection.up) {
if (positionToMove > 0) {
bodyComponentModels.swap(positionToMove - 1, positionToMove);
}
} else if (event.moveItemDirection == MoveItemDirection.down) {
if (positionToMove < bodyComponentModels.length - 1) {
bodyComponentModels.swap(positionToMove + 1, positionToMove);
}
}
emit(_newStateWithItems(bodyComponentModels,
currentlySelected: event.bodyComponentModel));
apply();
});
on<BodyComponentsUpdateItem>((event, emit) {
BodyComponentsCreateInitialised theState =
state as BodyComponentsCreateInitialised;
List<BodyComponentModel> bodyComponentModels =
List.of(theState.bodyComponentModels);
int positionToReplace =
bodyComponentModels.indexOf(event.beforeBodyComponentModel);
bodyComponentModels.replace(
positionToReplace, event.afterBodyComponentModel);
emit(_newStateWithItems(bodyComponentModels,
currentlySelected: event.afterBodyComponentModel));
apply();
});
on<BodyComponentsCreateAddBodyComponent>((event, emit) {
BodyComponentsCreateInitialised theState =
state as BodyComponentsCreateInitialised;
List<BodyComponentModel> bodyComponentModels =
List.of(theState.bodyComponentModels);
bodyComponentModels.add(event.bodyComponentModel);
emit(_newStateWithItems(bodyComponentModels,
currentlySelected: event.bodyComponentModel));
apply();
});
}