assignSource method

void assignSource(
  1. DiveSource? source,
  2. DiveReferencePanel? panel
)

Implementation

void assignSource(DiveSource? source, DiveReferencePanel? panel) {
  int panelIndex = state.panels!.indexOf(panel);
  assert(panelIndex >= 0 && panelIndex < DiveReferencePanels.maxPanelSources);
  if (panelIndex < 0 || panelIndex >= DiveReferencePanels.maxPanelSources) {
    print("DiveReferencePanelsCubit.assignSource panel not found: $panel");
    return;
  }

  final newState = state.copyWith(
      panels: state.panels!.rebuild((b) => b[panelIndex] = b[panelIndex]!.copyWith(assignedSource: source)));

  emit(newState);
}