Initial implementation of navigation from notification(not yet working)

This commit is contained in:
2026-03-01 17:59:23 +08:00
parent ed078f24ec
commit 294d3f7470
3 changed files with 124 additions and 16 deletions
+21
View File
@@ -1,9 +1,11 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:go_router/go_router.dart';
import '../models/notification_item.dart';
import '../providers/notifications_provider.dart';
import '../providers/notification_navigation_provider.dart';
/// Wraps the app and installs both a Supabase realtime listener and the
/// FCM handlers described in the frontend design.
@@ -112,6 +114,25 @@ class _NotificationBridgeState extends ConsumerState<NotificationBridge>
}
_prevList = nextList;
});
// Listen for pending navigation from notification taps
ref.listen<PendingNavigation?>(pendingNotificationNavigationProvider, (
previous,
next,
) {
if (next != null) {
final type = next.type;
final id = next.id;
if (type == 'ticket') {
GoRouter.of(context).go('/tickets/$id');
} else if (type == 'task') {
GoRouter.of(context).go('/tasks/$id');
}
// Clear the pending navigation after handling
ref.read(pendingNotificationNavigationProvider.notifier).state = null;
}
});
return widget.child;
}
}