import 'package:hydrated_bloc/hydrated_bloc.dart'; import '../../../../api/marianumconnect/queries/get_capabilities/guardian_child.dart'; /// The child a guardian is currently looking at. Shared by every module that /// shows per-child data (timetable, absence report, later messages), so /// switching the child in one place switches it everywhere. class ChildSelectionCubit extends HydratedCubit { ChildSelectionCubit() : super(null); void select(String childId) => emit(childId); Future reset() async => emit(null); @override String? fromJson(Map json) => json['childId'] as String?; @override Map? toJson(String? state) => {'childId': state}; } /// The selected child if it is still linked, otherwise the first one. Null /// when there are no children. GuardianChild? effectiveChild( List children, String? selectedId, ) { if (children.isEmpty) return null; for (final child in children) { if (child.id == selectedId) return child; } return children.first; }