Compare commits
2 Commits
main
...
Feature_Fi
Author | SHA1 | Date | |
---|---|---|---|
![]() |
0f67f4df74 | ||
![]() |
5fa4a67b0a |
@ -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.marcostage"
|
||||
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
|
||||
|
29
android/app/google-services.json
Normal file
29
android/app/google-services.json
Normal 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"
|
||||
}
|
@ -6,6 +6,8 @@
|
||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
|
||||
|
||||
|
||||
|
||||
@ -30,6 +32,9 @@
|
||||
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"/>
|
||||
|
@ -19,7 +19,8 @@ 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"
|
||||
|
@ -8,23 +8,33 @@ import 'package:marco/helpers/theme/app_theme.dart';
|
||||
import 'package:url_strategy/url_strategy.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/helpers/services/auth_service.dart';
|
||||
import 'package:firebase_core/firebase_core.dart';
|
||||
import 'package:marco/helpers/services/firebase_messaging_services.dart';
|
||||
|
||||
Future<void> initializeApp() async {
|
||||
try {
|
||||
logSafe("💡 Starting app initialization...");
|
||||
|
||||
// 1. Set Flutter web path URL strategy (optional but early)
|
||||
setPathUrlStrategy();
|
||||
logSafe("💡 URL strategy set.");
|
||||
|
||||
// 2. Set system UI overlays
|
||||
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
|
||||
statusBarColor: Color.fromARGB(255, 255, 0, 0),
|
||||
statusBarIconBrightness: Brightness.light,
|
||||
));
|
||||
logSafe("💡 System UI overlay style set.");
|
||||
|
||||
// 3. Initialize Firebase (should be before any Firebase service usage)
|
||||
await Firebase.initializeApp();
|
||||
logSafe("💡 Firebase initialized.");
|
||||
|
||||
// 4. Local storage
|
||||
await LocalStorage.init();
|
||||
logSafe("💡 Local storage initialized.");
|
||||
|
||||
// If a refresh token is found, try to refresh the JWT token
|
||||
// 5. Try to refresh JWT token if available
|
||||
final refreshToken = await LocalStorage.getRefreshToken();
|
||||
if (refreshToken != null && refreshToken.isNotEmpty) {
|
||||
logSafe("🔁 Refresh token found. Attempting to refresh JWT...");
|
||||
@ -32,15 +42,16 @@ Future<void> initializeApp() async {
|
||||
|
||||
if (!success) {
|
||||
logSafe("⚠️ Refresh token invalid or expired. Skipping controller injection.");
|
||||
// Optionally, clear tokens and force logout here if needed
|
||||
}
|
||||
} else {
|
||||
logSafe("❌ No refresh token found. Skipping refresh.");
|
||||
}
|
||||
|
||||
// 6. Initialize theme customization
|
||||
await ThemeCustomizer.init();
|
||||
logSafe("💡 Theme customizer initialized.");
|
||||
|
||||
// 7. Inject controllers if token is valid
|
||||
final token = LocalStorage.getString('jwt_token');
|
||||
if (token != null && token.isNotEmpty) {
|
||||
if (!Get.isRegistered<PermissionController>()) {
|
||||
@ -53,13 +64,18 @@ Future<void> initializeApp() async {
|
||||
logSafe("💡 ProjectController injected as permanent.");
|
||||
}
|
||||
|
||||
// Load data into controllers if required
|
||||
await Get.find<PermissionController>().loadData(token);
|
||||
await Get.find<ProjectController>().fetchProjects();
|
||||
} else {
|
||||
logSafe("⚠️ No valid JWT token found. Skipping controller initialization.");
|
||||
}
|
||||
|
||||
// 8. Firebase Messaging setup
|
||||
final notificationService = FirebaseNotificationService();
|
||||
await notificationService.initialize();
|
||||
logSafe("💡 Firebase Messaging initialized.");
|
||||
|
||||
// 9. App style setup
|
||||
AppStyle.init();
|
||||
logSafe("💡 AppStyle initialized.");
|
||||
|
||||
|
53
lib/helpers/services/firebase_messaging_services.dart
Normal file
53
lib/helpers/services/firebase_messaging_services.dart
Normal 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}');
|
||||
}
|
@ -77,6 +77,9 @@ dependencies:
|
||||
html_editor_enhanced: ^2.7.0
|
||||
flutter_quill_delta_from_html: ^1.5.2
|
||||
quill_delta: ^3.0.0-nullsafety.2
|
||||
firebase_core: ^3.14.0
|
||||
firebase_messaging: ^15.2.7
|
||||
googleapis_auth: ^2.0.0
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
|
Loading…
x
Reference in New Issue
Block a user