Update: 2026-05-06 04:55:22

This commit is contained in:
Hamza-Ayed
2026-05-06 04:55:22 +03:00
parent 0dcced4142
commit 01234bf3f2
14 changed files with 412 additions and 3 deletions

View File

@@ -0,0 +1,34 @@
import 'package:firebase_messaging/firebase_messaging.dart';
import '../utils/logger.dart';
class PushNotificationService {
static final FirebaseMessaging _fcm = FirebaseMessaging.instance;
static Future<void> initialize() async {
// 1. Request permissions (iOS)
NotificationSettings settings = await _fcm.requestPermission(
alert: true,
badge: true,
sound: true,
);
AppLogger.print('User granted permission: ${settings.authorizationStatus}');
// 2. Handle foreground messages
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
AppLogger.print('Received foreground message: ${message.notification?.title}');
// You can show a local notification here if needed
});
}
static Future<String?> getToken() async {
try {
String? token = await _fcm.getToken();
AppLogger.print('FCM Token: $token');
return token;
} catch (e) {
AppLogger.error('Failed to get FCM token', e);
return null;
}
}
}

View File

@@ -7,6 +7,7 @@ import '../../../core/storage/secure_storage.dart';
import '../../../app/routes/app_pages.dart';
import '../../../core/utils/logger.dart';
import '../../../core/utils/app_snackbar.dart';
import '../../../core/services/push_notification_service.dart';
class AuthController extends GetxController {
final Dio _dio = DioClient().client;
@@ -56,13 +57,17 @@ class AuthController extends GetxController {
deviceName = iosInfo.name;
}
// Get FCM token for notifications
final pushToken = await PushNotificationService.getToken();
final response = await _dio.post('auth/mobile/verify-otp', data: {
'phone': phone.value,
'otp': otp,
'device_id': deviceId,
'device_name': deviceName,
'platform': Platform.operatingSystem,
'app_version': '1.0.0', // TODO: Get from package_info_plus
'app_version': '1.0.0',
'push_token': pushToken,
});
if (response.statusCode == 200) {

View File

@@ -0,0 +1,68 @@
// File generated by FlutterFire CLI.
// ignore_for_file: type=lint
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
import 'package:flutter/foundation.dart'
show defaultTargetPlatform, kIsWeb, TargetPlatform;
/// Default [FirebaseOptions] for use with your Firebase apps.
///
/// Example:
/// ```dart
/// import 'firebase_options.dart';
/// // ...
/// await Firebase.initializeApp(
/// options: DefaultFirebaseOptions.currentPlatform,
/// );
/// ```
class DefaultFirebaseOptions {
static FirebaseOptions get currentPlatform {
if (kIsWeb) {
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for web - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
}
switch (defaultTargetPlatform) {
case TargetPlatform.android:
return android;
case TargetPlatform.iOS:
return ios;
case TargetPlatform.macOS:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for macos - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
case TargetPlatform.windows:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for windows - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
case TargetPlatform.linux:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for linux - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
default:
throw UnsupportedError(
'DefaultFirebaseOptions are not supported for this platform.',
);
}
}
static const FirebaseOptions android = FirebaseOptions(
apiKey: 'AIzaSyB7Gc_RNvFaFCsuN5acHK2SNkY5iMDecqk',
appId: '1:512384487867:android:eac271c0b0ea64b708749e',
messagingSenderId: '512384487867',
projectId: 'musadaq-c12ca',
storageBucket: 'musadaq-c12ca.firebasestorage.app',
);
static const FirebaseOptions ios = FirebaseOptions(
apiKey: 'AIzaSyBLKc35OqzY6oQA5507E2uHCCHQbRWAC_M',
appId: '1:512384487867:ios:03bd28c6088a4aa008749e',
messagingSenderId: '512384487867',
projectId: 'musadaq-c12ca',
storageBucket: 'musadaq-c12ca.firebasestorage.app',
iosBundleId: 'com.example.musadaqApp',
);
}

View File

@@ -1,12 +1,26 @@
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:firebase_core/firebase_core.dart';
import 'app/routes/app_pages.dart';
import 'core/services/push_notification_service.dart';
import 'app/theme/app_theme.dart';
@pragma('vm:entry-point')
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await Firebase.initializeApp();
debugPrint("Handling a background message: ${message.messageId}");
}
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// TODO: Initialize ObjectBox, SecureStorage, and DioClient here
// 1. Initialize Firebase & Notifications
await Firebase.initializeApp();
await PushNotificationService.initialize();
// 2. Register background handler
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
runApp(const MusadaqApp());
}