realtime controller
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
|
||||
import '../models/notification_item.dart';
|
||||
import '../providers/notifications_provider.dart';
|
||||
import '../providers/realtime_controller.dart';
|
||||
|
||||
/// Wraps the app and installs both a Supabase realtime listener and the
|
||||
/// FCM handlers described in the frontend design.
|
||||
@@ -24,21 +25,35 @@ class NotificationBridge extends ConsumerStatefulWidget {
|
||||
ConsumerState<NotificationBridge> createState() => _NotificationBridgeState();
|
||||
}
|
||||
|
||||
class _NotificationBridgeState extends ConsumerState<NotificationBridge> {
|
||||
class _NotificationBridgeState extends ConsumerState<NotificationBridge>
|
||||
with WidgetsBindingObserver {
|
||||
// store previous notifications to diff
|
||||
List<NotificationItem> _prevList = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
_setupFcmHandlers();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
super.didChangeAppLifecycleState(state);
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
try {
|
||||
// Trigger a best-effort realtime reconnection when the app resumes.
|
||||
ref.read(realtimeControllerProvider).recoverConnection();
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
|
||||
void _showBanner(String type, NotificationItem item) {
|
||||
final ctx = widget.navigatorKey.currentState?.overlay?.context;
|
||||
if (ctx == null) return;
|
||||
|
||||
Reference in New Issue
Block a user