StyleSelectionBloc constructor
StyleSelectionBloc(
- AppModel initialiseWithApp,
- FeedbackSelection? feedbackSelection
Implementation
StyleSelectionBloc(AppModel initialiseWithApp, this.feedbackSelection)
: app = initialiseWithApp.copyWith(),
super(StyleSelectionUninitialized()) {
on<InitialiseStyleSelectionEvent>((event, emit) {
styleName = app.styleName;
StyleFamily? styleFamily;
if (event.family != null) {
styleFamily = StyleRegistry.registry().styleFamily(event.family!);
} else {
styleFamily = StyleRegistry.registry()
.styleFamily(DefaultStyleFamily.defaultStyleFamilyName);
}
var families =
StyleRegistry.registry().registeredStyleFamilies.values.toList();
var styleFamilyStates = families.map((styleFamily) {
listenToStyleFamily(app.documentID, styleFamily);
return StyleFamilyState(styleFamily, []);
}).toList();
if (styleFamily != null) {
Style? style;
if (event.styleName != null) {
style = styleFamily.getStyle(app, event.styleName!);
} else {
style = styleFamily.getStyle(app, DefaultStyle.defaultStyleName);
}
if (style != null) {
emit(StyleSelectionInitializedWithSelection(
families: styleFamilyStates,
currentSelectedStyle: style,
));
return;
}
}
emit(StyleSelectionInitializedWithoutSelection(
families: styleFamilyStates,
));
});
on<ChangedStyleFamilyState>((event, emit) {
if (state is StyleSelectionInitialized) {
var styleSelectionInitialized = state as StyleSelectionInitialized;
var styleFamily = event.styleFamily;
var styles = event.allStyles;
emit(styleSelectionInitialized.copyWithNewStyleFamily(
styleFamily, styles));
}
});
on<AddNewStyleEvent>((event, emit) async {
await event.styleFamily.newStyle(app, event.newStyleName);
});
on<SelectStyleEvent>((event, emit) {
emit(selectStyle(event.style, state as StyleSelectionInitialized));
});
on<DeleteStyleEvent>((event, emit) async {
await event.style.styleFamily.delete(app, event.style);
});
on<StyleUpdatedEvent>((event, emit) async {
await event.style.styleFamily.update(app, event.style);
});
on<CopyStyleEvent>((event, emit) async {
await event.style.copy(app, event.newName);
});
on<StyleSelectionApplyChanges>((event, emit) async {
if (event.save) {
await appRepository(appId: app.documentID)!.update(app);
}
});
}