OLD:
@override
void initState() {
super.initState();
_tabController = TabController(length: 2, vsync: this);
_loadParentData();
Future.delayed(Duration.zero, () async {
final uid = await AuthService.getCurrentUserId();
if (uid != null && mounted) {
context.read<LinkingStateNotifier>().initialize(uid);
}
});
}NEW:
@override
void initState() {
super.initState();
_tabController = TabController(length: 2, vsync: this);
_loadParentData();
// Initialize LinkingStateNotifier with parent ID
Future.delayed(Duration.zero, () async {
final uid = await AuthService.getCurrentUserId();
if (uid != null && mounted) {
final notifier = context.read<LinkingStateNotifier>();
notifier.initialize(uid);
// FIX: Listen to linking state changes and update local list
notifier.addListener(_syncLinkedChildrenFromNotifier);
}
});
}OLD:
void dispose() {
_tabController.dispose();
super.dispose();
}NEW:
@override
void dispose() {
_tabController.dispose();
// FIX: Remove listener when screen closes
try {
context.read<LinkingStateNotifier>().removeListener(_syncLinkedChildrenFromNotifier);
} catch (_) {}
super.dispose();
}/// FIX: Sync local _linkedChildren with LinkingStateNotifier when it changes
/// This ensures buttons and dialogs show correct children immediately after linking
void _syncLinkedChildrenFromNotifier() {
final notifier = context.read<LinkingStateNotifier>();
setState(() {
_linkedChildren = notifier.linkedChildren
.map((linkedChild) => {
'username': linkedChild.childUsername,
'personalId': linkedChild.childEmail,
'uid': linkedChild.childId,
'linkedAt': linkedChild.linkedAt,
})
.toList();
});
print('✅ Synced local _linkedChildren from notifier: ${_linkedChildren.length} children');
}- LinkingService ✅ (unchanged)
- LinkingStateNotifier ✅ (unchanged)
- ChildLinkingScreen ✅ (unchanged)
- TaskSyncService ✅ (unchanged)
- Firestore rules ✅ (unchanged)
- UI buttons & dialogs ✅ (unchanged - they now just receive correct data)
- Open
lib/Screens/parent_dashboard.dart - Locate the existing
initState()method (around line 45-55) - Add
notifier.addListener(_syncLinkedChildrenFromNotifier);in the initialization - Locate the existing
dispose()method (around line 538-545) - Add the listener removal and @override decorator
- Insert the new
_syncLinkedChildrenFromNotifier()method right afterdispose() - Save and rebuild:
flutter build windows
Done. No other changes needed.