diff --git a/android/app/build.gradle b/android/app/build.gradle
index ef80cbe..cc00113 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -3,6 +3,16 @@ plugins {
id "kotlin-android"
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id "dev.flutter.flutter-gradle-plugin"
+ id("com.google.gms.google-services")
+}
+dependencies {
+// Import the Firebase BoM
+implementation(platform("com.google.firebase:firebase-bom:33.15.0"))
+// TODO: Add the dependencies for Firebase products you want to use
+// When using the BoM, don't specify versions in Firebase dependencies
+implementation("com.google.firebase:firebase-analytics")
+// Add the dependencies for any other desired Firebase products
+// https://firebase.google.com/docs/android/setup#available-libraries
}
android {
@@ -21,7 +31,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
- applicationId = "com.example.marco"
+ applicationId = "com.marcoaiot.marcopms"
// You can update the following values to match your application needs.
// For more information, see: https://flutter.dev/to/review-gradle-config.
minSdk = flutter.minSdkVersion
diff --git a/android/app/google-services.json b/android/app/google-services.json
new file mode 100644
index 0000000..9181160
--- /dev/null
+++ b/android/app/google-services.json
@@ -0,0 +1,29 @@
+{
+ "project_info": {
+ "project_number": "1092827913328",
+ "project_id": "marcopms-mobileapp",
+ "storage_bucket": "marcopms-mobileapp.firebasestorage.app"
+ },
+ "client": [
+ {
+ "client_info": {
+ "mobilesdk_app_id": "1:1092827913328:android:2c70d4f75f334a572ae8b5",
+ "android_client_info": {
+ "package_name": "com.marcoaiot.marcopms"
+ }
+ },
+ "oauth_client": [],
+ "api_key": [
+ {
+ "current_key": "AIzaSyAugYA2UsQewE-Yd6LBU90hWb2W6NkiMpU"
+ }
+ ],
+ "services": {
+ "appinvite_service": {
+ "other_platform_oauth_client": []
+ }
+ }
+ }
+ ],
+ "configuration_version": "1"
+}
\ No newline at end of file
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index a93d51b..d640d6d 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -3,6 +3,9 @@
+
+
+
@@ -27,6 +30,10 @@
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
+
+
diff --git a/android/settings.gradle b/android/settings.gradle
index a42444d..eb71b1f 100644
--- a/android/settings.gradle
+++ b/android/settings.gradle
@@ -19,7 +19,9 @@ pluginManagement {
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.2.1" apply false
- id "org.jetbrains.kotlin.android" version "1.8.22" apply false
+ id "org.jetbrains.kotlin.android" version "2.1.0" apply false
+ id("com.google.gms.google-services") version "4.4.2" apply false
+
}
include ":app"
diff --git a/devtools_options.yaml b/devtools_options.yaml
new file mode 100644
index 0000000..fa0b357
--- /dev/null
+++ b/devtools_options.yaml
@@ -0,0 +1,3 @@
+description: This file stores settings for Dart & Flutter DevTools.
+documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
+extensions:
diff --git a/lib/helpers/services/firebase_messaging_service.dart b/lib/helpers/services/firebase_messaging_service.dart
new file mode 100644
index 0000000..9e9b9bb
--- /dev/null
+++ b/lib/helpers/services/firebase_messaging_service.dart
@@ -0,0 +1,53 @@
+import 'package:firebase_core/firebase_core.dart';
+import 'package:firebase_messaging/firebase_messaging.dart';
+import 'package:logger/logger.dart';
+
+class FirebaseNotificationService {
+ final FirebaseMessaging _firebaseMessaging = FirebaseMessaging.instance;
+ final Logger _logger = Logger();
+
+ Future initialize() async {
+ await Firebase.initializeApp();
+ _logger.i('Firebase initialized.');
+
+ NotificationSettings settings = await _firebaseMessaging.requestPermission();
+ _logger.i('FCM permission status: ${settings.authorizationStatus}');
+
+ // Foreground messages
+ FirebaseMessaging.onMessage.listen((RemoteMessage message) {
+ _logger.i('🔔 Foreground Notification Received');
+ _logNotificationDetails(message);
+ });
+
+ // When app is opened from background via notification
+ FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
+ _logger.i('📲 App opened via notification');
+ _handleNotificationTap(message);
+ });
+
+ // Background handler registration
+ FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
+ }
+
+ void _handleNotificationTap(RemoteMessage message) {
+ _logger.i('Notification tapped with data: ${message.data}');
+ }
+
+ void _logNotificationDetails(RemoteMessage message) {
+ _logger.i('Notification ID: ${message.messageId}');
+ _logger.i('Title: ${message.notification?.title}');
+ _logger.i('Body: ${message.notification?.body}');
+ _logger.i('Data: ${message.data}');
+ }
+}
+
+// Background handler
+Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
+ await Firebase.initializeApp();
+ final Logger _logger = Logger();
+ _logger.i('🕓 Handling background notification...');
+ _logger.i('Notification ID: ${message.messageId}');
+ _logger.i('Title: ${message.notification?.title}');
+ _logger.i('Body: ${message.notification?.body}');
+ _logger.i('Data: ${message.data}');
+}
diff --git a/lib/main.dart b/lib/main.dart
index 1b5de88..840be3b 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -14,6 +14,9 @@ import 'package:url_strategy/url_strategy.dart';
import 'package:marco/helpers/services/auth_service.dart';
import 'package:flutter/services.dart';
import 'package:logger/logger.dart';
+import 'package:firebase_core/firebase_core.dart';
+import 'package:marco/helpers/services/firebase_messaging_service.dart';
+
final Logger logger = Logger();
Future main() async {
@@ -28,6 +31,9 @@ Future main() async {
try {
await LocalStorage.init();
await ThemeCustomizer.init();
+ await Firebase.initializeApp();
+ final notificationService = FirebaseNotificationService();
+ await notificationService.initialize();
AppStyle.init();
logger.i("App initialization completed successfully.");
} catch (e, stacktrace) {
diff --git a/pubspec.yaml b/pubspec.yaml
index 0c536d2..8914bae 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -69,6 +69,9 @@ dependencies:
path: ^1.9.0
percent_indicator: ^4.2.2
flutter_contacts: ^1.1.9+2
+ firebase_core: ^3.14.0
+ firebase_messaging: ^15.2.7
+ googleapis_auth: ^2.0.0
dev_dependencies:
flutter_test:
sdk: flutter