Initial implementation of navigation from notification(not yet working)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user