added guardian login with views for their assigned childs
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
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<String?> {
|
||||
ChildSelectionCubit() : super(null);
|
||||
|
||||
void select(String childId) => emit(childId);
|
||||
|
||||
Future<void> reset() async => emit(null);
|
||||
|
||||
@override
|
||||
String? fromJson(Map<String, dynamic> json) => json['childId'] as String?;
|
||||
|
||||
@override
|
||||
Map<String, dynamic>? 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<GuardianChild> children,
|
||||
String? selectedId,
|
||||
) {
|
||||
if (children.isEmpty) return null;
|
||||
for (final child in children) {
|
||||
if (child.id == selectedId) return child;
|
||||
}
|
||||
return children.first;
|
||||
}
|
||||
Reference in New Issue
Block a user