mobile bluesky app made with flutter lazurite.stormlightlabs.org/
mobile bluesky flutter
at main 65 lines 2.1 kB view raw
1import 'package:flutter/material.dart'; 2import 'package:flutter_local_notifications/flutter_local_notifications.dart'; 3import 'package:go_router/go_router.dart'; 4import 'package:lazurite/src/core/infrastructure/notifications/notification_initializer.dart'; 5 6/// Service for handling notification interactions and deep linking. 7/// 8/// This singleton manages: 9/// - Notification tap handling with deep linking to scheduled posts 10/// - Integration with the app's router for navigation 11class NotificationController { 12 NotificationController._(); 13 14 static final _instance = NotificationController._(); 15 static NotificationController get instance => _instance; 16 17 GlobalKey<NavigatorState>? _navigatorKey; 18 19 /// Initializes the notification controller with the app's navigator key. 20 /// 21 /// This must be called after the router is initialized. 22 void initialize({GlobalKey<NavigatorState>? navigatorKey}) { 23 _navigatorKey = navigatorKey; 24 NotificationInitializer.instance.setOnNotificationTapCallback(_onNotificationTap); 25 debugPrint('NotificationController initialized'); 26 } 27 28 /// Handles notification tap events. 29 void _onNotificationTap(NotificationResponse response) { 30 final payload = response.payload; 31 32 if (payload == null) { 33 debugPrint('Notification tapped with no payload'); 34 return; 35 } 36 37 debugPrint('Notification tapped with payload: $payload'); 38 39 if (payload.startsWith('draft:')) { 40 final draftId = payload.substring(6); 41 _navigateToScheduledPost(draftId); 42 } 43 } 44 45 /// Navigates to the scheduled post detail screen. 46 void _navigateToScheduledPost(String draftId) { 47 if (_navigatorKey == null) { 48 debugPrint('No navigator key available for scheduled post: $draftId'); 49 return; 50 } 51 52 final context = _navigatorKey!.currentContext; 53 54 if (context == null) { 55 debugPrint('No navigation context available for scheduled post: $draftId'); 56 return; 57 } 58 59 try { 60 context.go('/scheduled/$draftId'); 61 } catch (e) { 62 debugPrint('Failed to navigate to scheduled post: $e'); 63 } 64 } 65}