feat: implement Stripe checkout flow, update profile settings UI for subscriptions, and add agent profile editing.
This commit is contained in:
@@ -19,9 +19,8 @@ class PushNotificationService {
|
||||
factory PushNotificationService() => _instance;
|
||||
PushNotificationService._internal();
|
||||
|
||||
final FirebaseMessaging _messaging = FirebaseMessaging.instance;
|
||||
final FlutterLocalNotificationsPlugin _localNotifications =
|
||||
FlutterLocalNotificationsPlugin();
|
||||
FirebaseMessaging? _messaging;
|
||||
FlutterLocalNotificationsPlugin? _localNotifications;
|
||||
final NotificationRepository _repo = NotificationRepository();
|
||||
|
||||
String? _currentToken;
|
||||
@@ -31,15 +30,26 @@ class PushNotificationService {
|
||||
void Function(String? actionUrl)? onNotificationTap;
|
||||
|
||||
/// Initialize Firebase Messaging and local notifications.
|
||||
/// Skipped on iOS until Firebase iOS app is configured.
|
||||
Future<void> initialize() async {
|
||||
if (_initialized) return;
|
||||
|
||||
// Skip on iOS — no Firebase iOS app configured yet
|
||||
if (Platform.isIOS) {
|
||||
debugPrint('[FCM] Skipped on iOS — no Firebase iOS app configured');
|
||||
return;
|
||||
}
|
||||
|
||||
_initialized = true;
|
||||
|
||||
_messaging = FirebaseMessaging.instance;
|
||||
_localNotifications = FlutterLocalNotificationsPlugin();
|
||||
|
||||
// Register background handler
|
||||
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
|
||||
|
||||
// Request permission
|
||||
final settings = await _messaging.requestPermission(
|
||||
final settings = await _messaging!.requestPermission(
|
||||
alert: true,
|
||||
badge: true,
|
||||
sound: true,
|
||||
@@ -58,7 +68,7 @@ class PushNotificationService {
|
||||
await _getAndRegisterToken();
|
||||
|
||||
// Listen for token refresh
|
||||
_messaging.onTokenRefresh.listen(_onTokenRefresh);
|
||||
_messaging!.onTokenRefresh.listen(_onTokenRefresh);
|
||||
|
||||
// Handle foreground messages
|
||||
FirebaseMessaging.onMessage.listen(_onForegroundMessage);
|
||||
@@ -67,14 +77,14 @@ class PushNotificationService {
|
||||
FirebaseMessaging.onMessageOpenedApp.listen(_onMessageOpenedApp);
|
||||
|
||||
// Check if app was opened from a terminated state notification
|
||||
final initialMessage = await _messaging.getInitialMessage();
|
||||
final initialMessage = await _messaging!.getInitialMessage();
|
||||
if (initialMessage != null) {
|
||||
_onMessageOpenedApp(initialMessage);
|
||||
}
|
||||
|
||||
// iOS: set foreground notification presentation options
|
||||
if (Platform.isIOS) {
|
||||
await _messaging.setForegroundNotificationPresentationOptions(
|
||||
await _messaging!.setForegroundNotificationPresentationOptions(
|
||||
alert: true,
|
||||
badge: true,
|
||||
sound: true,
|
||||
@@ -90,7 +100,7 @@ class PushNotificationService {
|
||||
importance: Importance.high,
|
||||
);
|
||||
|
||||
await _localNotifications
|
||||
await _localNotifications!
|
||||
.resolvePlatformSpecificImplementation<
|
||||
AndroidFlutterLocalNotificationsPlugin>()
|
||||
?.createNotificationChannel(androidChannel);
|
||||
@@ -103,7 +113,7 @@ class PushNotificationService {
|
||||
requestSoundPermission: false,
|
||||
);
|
||||
|
||||
await _localNotifications.initialize(
|
||||
await _localNotifications!.initialize(
|
||||
const InitializationSettings(
|
||||
android: androidSettings,
|
||||
iOS: iosSettings,
|
||||
@@ -117,7 +127,7 @@ class PushNotificationService {
|
||||
|
||||
Future<void> _getAndRegisterToken() async {
|
||||
try {
|
||||
final token = await _messaging.getToken();
|
||||
final token = await _messaging!.getToken();
|
||||
if (token != null) {
|
||||
_currentToken = token;
|
||||
debugPrint('[FCM] Token: $token');
|
||||
@@ -151,7 +161,7 @@ class PushNotificationService {
|
||||
|
||||
// Show local notification on Android (iOS handles it natively)
|
||||
if (Platform.isAndroid) {
|
||||
_localNotifications.show(
|
||||
_localNotifications?.show(
|
||||
notification.hashCode,
|
||||
notification.title,
|
||||
notification.body,
|
||||
@@ -178,7 +188,7 @@ class PushNotificationService {
|
||||
|
||||
/// Unregister FCM token from backend (call on logout).
|
||||
Future<void> unregister() async {
|
||||
if (_currentToken == null) return;
|
||||
if (Platform.isIOS || _currentToken == null) return;
|
||||
try {
|
||||
await _repo.removeFcmToken(_currentToken!);
|
||||
debugPrint('[FCM] Token unregistered from backend');
|
||||
@@ -190,6 +200,7 @@ class PushNotificationService {
|
||||
|
||||
/// Re-register token after login.
|
||||
Future<void> registerAfterLogin() async {
|
||||
if (Platform.isIOS) return;
|
||||
await _getAndRegisterToken();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user