updateVariable method

void updateVariable(
  1. ID cubitID,
  2. ID stateID,
  3. Variable variable
)

Implementation

void updateVariable(
  ID cubitID,
  ID stateID,
  Variable variable,
) {
  final cubit = state.getCubitByID(cubitID);
  final cubitState = cubit.states[stateID];
  final newCubitState = cubitState?.copyWith(
    fields: {
      ...cubitState.fields,
      variable.id: variable,
    },
  );
  emit(state.copyWith(
    instantiatedCubits: {
      ...state.instantiatedCubits,
      cubitID: cubit.copyWith(
        states: {
          ...cubit.states,
          stateID: newCubitState!,
        },
      ),
    },
  ));
  _cubitUpdateController.add(CubitUpdate(
    cubit.id,
    cubit.copyWith(
      states: {
        ...cubit.states,
        stateID: newCubitState,
      },
    ),
  ));
}