getVariableById method

VariableCubitInfoEntity getVariableById({
  1. required ID variableID,
  2. required ID cubitID,
  3. required ID stateID,
})

Implementation

VariableCubitInfoEntity getVariableById(
    {required ID variableID, required ID cubitID, required ID stateID}) {
  final cubit = state.getCubitByID(cubitID);

  final cubitState = cubit.states[stateID];
  if (cubitState == null) {
    Logger.printError('State not found in cubit');
    throw Exception('State not found in AppCubit');
  }

  final variable = cubitState.fields[variableID];
  if (variable == null) {
    Logger.printError('Variable not found in state');
    throw Exception('Variable not found in AppCubit');
  }

  return VariableCubitInfoEntity(
      cubitID: cubitID,
      stateID: stateID,
      cubitName: cubit.name,
      stateName: cubitState.name,
      variable: variable);
}