Compare commits

...

1 Commits

8 changed files with 115 additions and 2 deletions

View File

@ -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

View File

@ -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"
}

View File

@ -3,6 +3,9 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
@ -27,6 +30,10 @@
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="high_importance_channel"/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>

View File

@ -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"

3
devtools_options.yaml Normal file
View File

@ -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:

View File

@ -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<void> 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<void> _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}');
}

View File

@ -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<void> main() async {
@ -28,6 +31,9 @@ Future<void> 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) {

View File

@ -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