Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class InitOnActiveEnv {
);

// Register BottomNavManager in active environment scope so it's always available
di.registerSingleton<BottomNavManager>(BottomNavManager());
di.registerSingleton<BottomNavManager>(
BottomNavManager(),
dispose: (bottomNavManager) => bottomNavManager.dispose(),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class SchooldayEventListPage extends WatchingWidget {

@override
Widget build(BuildContext context) {
final _schooldayEventManager = di<SchooldayEventManager>();
//-TODO: Filterstate in SchooldayEventSearchbar and SchooldayEventListPageBottomNavBar

List<PupilProxy> pupils = watchValue((PupilsFilter x) => x.filteredPupils);
Expand All @@ -30,7 +29,8 @@ class SchooldayEventListPage extends WatchingWidget {
title: 'Ereignisse',
),
body: RefreshIndicator(
onRefresh: () async => _schooldayEventManager.fetchSchooldayEvents(),
onRefresh: () async =>
di<SchooldayEventManager>().fetchSchooldayEvents(),
child: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 700),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import 'package:flutter/foundation.dart';
import 'package:logging/logging.dart';

final _log = Logger('[BottomNavManager]');

class BottomNavManager {
final _bottomNavState = ValueNotifier<int>(0);
Expand All @@ -17,5 +20,12 @@ class BottomNavManager {

void setPupilProfileNavPage(int index) {
_pupilProfileNavState.value = index;
_log.info('PupilProfileNavPage set to $index');
}

void dispose() {
_bottomNavState.dispose();
_pupilProfileNavState.dispose();
_log.info('BottomNavManager disposed');
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:school_data_hub_flutter/core/models/datetime_extensions.dart';
import 'package:school_data_hub_flutter/common/theme/app_colors.dart';
import 'package:school_data_hub_flutter/common/widgets/custom_expansion_tile/custom_expansion_tile.dart';
import 'package:school_data_hub_flutter/common/widgets/custom_expansion_tile/custom_expansion_tile_content.dart';
import 'package:school_data_hub_flutter/core/models/datetime_extensions.dart';
import 'package:school_data_hub_flutter/features/app_main_navigation/domain/main_menu_bottom_nav_manager.dart';
import 'package:school_data_hub_flutter/features/learning_support/domain/learning_support_helper.dart';
import 'package:school_data_hub_flutter/features/learning_support/presentation/learning_support_list_page/widgets/support_category_status_batches.dart';
import 'package:school_data_hub_flutter/features/learning_support/presentation/learning_support_list_page/widgets/support_goals_list.dart';
import 'package:school_data_hub_flutter/features/pupil/domain/models/pupil_proxy.dart';
Expand All @@ -14,8 +13,6 @@ import 'package:school_data_hub_flutter/features/pupil/presentation/pupil_profil
import 'package:school_data_hub_flutter/features/pupil/presentation/widgets/avatar.dart';
import 'package:watch_it/watch_it.dart';

final _mainMenuBottomNavManager = di<BottomNavManager>();

class LearningSupportCard extends WatchingStatefulWidget {
final PupilProxy pupil;
const LearningSupportCard(this.pupil, {super.key});
Expand Down Expand Up @@ -63,12 +60,9 @@ class _LearningSupportCardState extends State<LearningSupportCard> {
scrollDirection: Axis.horizontal,
child: InkWell(
onTap: () {
_mainMenuBottomNavManager
.setPupilProfileNavPage(
ProfileNavigationState
.learningSupport
.value,
);
di<BottomNavManager>().setPupilProfileNavPage(
ProfileNavigationState.learningSupport.value,
);
Navigator.of(context).push(
MaterialPageRoute(
builder: (ctx) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ class PupilIdentityStream {
.listen(
(PupilIdentityDto event) async {
final eventSender = event.sender;

// Defensive null check - validate sender before processing
if (eventSender == null || eventSender.isEmpty) {
_log.severe(
'[${role.name.toUpperCase()}]: Received event with NULL/EMPTY sender! '
'Type: ${event.type}, Value: ${event.value}. Skipping malformed event.',
);
// Skip processing this malformed event
return;
}

_log.info(
'[${role.name.toUpperCase()}]: [${event.type}] Received event from $eventSender',
);
Expand Down Expand Up @@ -94,6 +105,16 @@ class PupilIdentityStream {
final targetUser = event.value.isNotEmpty
? event.value
: null;

// Validate user session before sending data

if (currentUser == null || currentUser.isEmpty) {
_log.severe(
'[${role.name.toUpperCase()}]: Cannot send data - username is null or empty',
);
break;
}

if (targetUser == null) {
// Legacy: no targeting, proceed for any receiver
if (onRequestConfirmed != null) {
Expand All @@ -103,8 +124,7 @@ class PupilIdentityStream {
await _client.pupilIdentity.sendPupilIdentityMessage(
channelName,
PupilIdentityDto(
sender:
di<HubSessionManager>().user!.userInfo!.userName!,
sender: currentUser,
dataTimeStamp:
di<EnvManager>().activeEnv?.lastIdentitiesUpdate,
type: 'data',
Expand All @@ -126,8 +146,7 @@ class PupilIdentityStream {
await _client.pupilIdentity.sendPupilIdentityMessage(
channelName,
PupilIdentityDto(
sender:
di<HubSessionManager>().user!.userInfo!.userName!,
sender: currentUser,
type: 'data',
dataTimeStamp:
di<EnvManager>().activeEnv?.lastIdentitiesUpdate,
Expand Down Expand Up @@ -283,12 +302,21 @@ class PupilIdentityStream {
lastIdentitiesUpdate: event.dataTimeStamp?.toUtc(),
);

// Validate user session before sending confirmation
final confirmUser =
di<HubSessionManager>().user?.userInfo?.userName;
if (confirmUser == null || confirmUser.isEmpty) {
_log.severe(
'[${role.name.toUpperCase()}]: Cannot send confirmation - username is null or empty',
);
break;
}

// Send confirmation
await _client.pupilIdentity.sendPupilIdentityMessage(
channelName,
PupilIdentityDto(
sender:
di<HubSessionManager>().user!.userInfo!.userName!,
sender: confirmUser,
type: 'ok',
value: '',
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import 'package:school_data_hub_flutter/features/pupil/presentation/pupil_profil
import 'package:school_data_hub_flutter/features/pupil/presentation/widgets/avatar.dart';
import 'package:watch_it/watch_it.dart';

final _mainMenuBottomNavManager = di<BottomNavManager>();

class CreditListCard extends WatchingWidget {
final PupilProxy pupil;
const CreditListCard(this.pupil, {super.key});
Expand Down Expand Up @@ -57,8 +55,9 @@ class CreditListCard extends WatchingWidget {
scrollDirection: Axis.horizontal,
child: InkWell(
onTap: () {
_mainMenuBottomNavManager
.setPupilProfileNavPage(2);
di<BottomNavManager>().setPupilProfileNavPage(
2,
);
Navigator.of(context).push(
MaterialPageRoute(
builder: (ctx) =>
Expand Down
Loading