diff --git a/android/app/google-services.json b/android/app/google-services.json new file mode 100644 index 0000000..a265ce5 --- /dev/null +++ b/android/app/google-services.json @@ -0,0 +1,29 @@ +{ + "project_info": { + "project_number": "598107454568", + "project_id": "cargo66", + "storage_bucket": "cargo66.appspot.com" + }, + "client": [ + { + "client_info": { + "mobilesdk_app_id": "1:598107454568:android:b2b6e38663f71e9e314fdd", + "android_client_info": { + "package_name": "com.cargo66.com" + } + }, + "oauth_client": [], + "api_key": [ + { + "current_key": "AIzaSyB4aGhjQIDs6neCWrrITI6iujKhKm2Y9cg" + } + ], + "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 29fb761..054c2e8 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -4,6 +4,15 @@ android:label="Cargo 66" android:name="${applicationName}" android:icon="@mipmap/launcher_icon"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png index db77bb4..54c5e47 100644 Binary files a/android/app/src/main/res/mipmap-hdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png index 17987b7..8b8b89a 100644 Binary files a/android/app/src/main/res/mipmap-mdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png index 09d4391..a28d220 100644 Binary files a/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png index d5f1c8d..1b13af5 100644 Binary files a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png index 4d6372e..6ee03ad 100644 Binary files a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..3132450 --- /dev/null +++ b/android/app/src/main/res/values/strings.xml @@ -0,0 +1,4 @@ + + + default_channel_id + \ No newline at end of file diff --git a/ios/Runner/GoogleService-Info.plist b/ios/Runner/GoogleService-Info.plist new file mode 100644 index 0000000..9efcb3f --- /dev/null +++ b/ios/Runner/GoogleService-Info.plist @@ -0,0 +1,30 @@ + + + + + API_KEY + AIzaSyCMbx3GD8XMCI9vdrQvIy6nTr-kiNx2f9k + GCM_SENDER_ID + 598107454568 + PLIST_VERSION + 1 + BUNDLE_ID + com.example.cargo + PROJECT_ID + cargo66 + STORAGE_BUCKET + cargo66.appspot.com + IS_ADS_ENABLED + + IS_ANALYTICS_ENABLED + + IS_APPINVITE_ENABLED + + IS_GCM_ENABLED + + IS_SIGNIN_ENABLED + + GOOGLE_APP_ID + 1:598107454568:ios:3bbcc27922926fe7314fdd + + \ No newline at end of file diff --git a/ios/firebase_app_id_file.json b/ios/firebase_app_id_file.json new file mode 100644 index 0000000..7a96f5a --- /dev/null +++ b/ios/firebase_app_id_file.json @@ -0,0 +1,7 @@ +{ + "file_generated_by": "FlutterFire CLI", + "purpose": "FirebaseAppID & ProjectID for this Firebase app in this directory", + "GOOGLE_APP_ID": "1:598107454568:ios:3bbcc27922926fe7314fdd", + "FIREBASE_PROJECT_ID": "cargo66", + "GCM_SENDER_ID": "598107454568" +} \ No newline at end of file diff --git a/lib/core/utils/download_file.dart b/lib/core/utils/download_file.dart new file mode 100644 index 0000000..8b5da31 --- /dev/null +++ b/lib/core/utils/download_file.dart @@ -0,0 +1,25 @@ +import 'dart:io'; +import 'package:http/http.dart' as http; +import 'package:path_provider/path_provider.dart'; + +Future downloadFile(String url, String filename) async { + final directory = await getApplicationDocumentsDirectory(); + final filePath = '${directory.path}/$filename'; + + // Perform the GET request + final response = await http.get(Uri.parse(url)); + + // Check if the request was successful + if (response.statusCode == 200) { + final file = File(filePath); + + var raf = file.openSync(mode: FileMode.write); + // response.bodyBytes is a List type + raf.writeFromSync(response.bodyBytes); + await raf.close(); + + return filePath; + } else { + throw Exception('Failed to download file'); + } +} diff --git a/lib/core/utils/notification_service.dart b/lib/core/utils/notification_service.dart new file mode 100644 index 0000000..1727667 --- /dev/null +++ b/lib/core/utils/notification_service.dart @@ -0,0 +1,284 @@ +import 'dart:io'; + +import 'package:cargo/core/constants/colors.dart'; +import 'package:firebase_core/firebase_core.dart'; +import 'package:firebase_messaging/firebase_messaging.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter_local_notifications/flutter_local_notifications.dart'; +import 'package:permission_handler/permission_handler.dart'; + +import '../../../firebase_options.dart'; +import 'download_file.dart'; + +class FCMFunctions { + static final FCMFunctions _singleton = FCMFunctions._internal(); + + FCMFunctions._internal(); + + factory FCMFunctions() { + return _singleton; + } + + late FirebaseMessaging messaging; + + late FlutterLocalNotificationsPlugin flip; + + late InitializationSettings initSettings; +//************************************************************************************************************ */ + /// Create a [AndroidNotificationChannel] for heads up notifications + late AndroidNotificationChannel channel; + + /// Initialize the [FlutterLocalNotificationsPlugin] package. + late FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin; + +//************************************************************************************************************ */ + + Future initApp() async { + debugPrint('init firebase'); + + if (Platform.isAndroid) { + if (await Permission.notification.isDenied) { + await Permission.notification.request(); + } + } + + await Firebase.initializeApp( + options: DefaultFirebaseOptions.currentPlatform, + ); + + messaging = FirebaseMessaging.instance; + + if (!kIsWeb) { + channel = const AndroidNotificationChannel( + 'high_importance_channel', // id + 'High Importance Notifications', // title + importance: Importance.high, + ); + + flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); + + /// Create an Android Notification Channel. + /// + /// We use this channel in the `AndroidManifest.xml` file to override the + /// default FCM channel to enable heads up notifications. + await flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation() + ?.createNotificationChannel(channel); + + //for IOS Foreground Notification + await messaging.setForegroundNotificationPresentationOptions( + alert: true, + badge: true, + sound: true, + ); + + flip = FlutterLocalNotificationsPlugin(); + var initializationSettingsAndroid = const AndroidInitializationSettings('@mipmap/launcher_icon'); + var initializationSettingsIOs = const DarwinInitializationSettings(); + initSettings = InitializationSettings(android: initializationSettingsAndroid, iOS: initializationSettingsIOs); + } + } + + Future subscribeToTopics(String topic) async { + await messaging.subscribeToTopic(topic); + } + + ///Expire : https://firebase.google.com/docs/cloud-messaging/manage-tokens + Future getFCMToken() async { + final fcmToken = await messaging.getToken(); + debugPrint('Get FCM Token ------->: $fcmToken'); + return fcmToken; + } + + void tokenListener() { + debugPrint('tokenListener'); + messaging.onTokenRefresh.listen((fcmToken) { + debugPrint('Listen FCM Token ------->: $fcmToken'); + // If necessary send token to application server. + }).onError((err) { + debugPrint('tokenListener err $err'); + }); + } + + /// IOS + Future iosWebPermission() async { + if (Platform.isIOS || kIsWeb) { + NotificationSettings settings = await messaging.requestPermission(); + } + } + + ///Foreground messages + /// + ///To handle messages while your application is in the foreground, listen to the onMessage stream. + void foreGroundMessageListener() { + FirebaseMessaging.onMessage.listen(_onMessageHandler); + FirebaseMessaging.onMessageOpenedApp.listen(_onMessageOpenedApp); + } + + // foreground + Future _onMessageHandler(RemoteMessage message) async { + debugPrint('onMessageHandler'); + _showNotificationViaFBConsole(message); + // fcmFunctions._showNotification(message); + } + + // FLUTTER_NOTIFICATION_CLICK + + // background (app minimized) + Future _onMessageOpenedApp(RemoteMessage message) async => _performClickAction(message); + + Future _showNotification(RemoteMessage message) async { + final RemoteNotification? notification = message.notification; + if (notification == null) return; + + final String? imgUrl = _getImageUrl(notification); + + debugPrint('==> imgUrl: $imgUrl '); + + BigPictureStyleInformation? styleInformation; + if (imgUrl != null) { + final largeIconPath = await downloadFile(imgUrl, 'largeIcon'); + final bigPicturePath = await downloadFile(imgUrl, 'bigPicture'); + + styleInformation = BigPictureStyleInformation( + FilePathAndroidBitmap(bigPicturePath), + largeIcon: FilePathAndroidBitmap(largeIconPath), + ); + } + + try { + var androidPlatformChannelSpecifics = AndroidNotificationDetails( + channel.id, + channel.name, + icon: '@mipmap/launcher_icon', + channelDescription: channel.description, + importance: Importance.max, + priority: Priority.high, + color: AppColors.primary, + styleInformation: styleInformation, + ); + var iOSPlatformChannelSpecifics = const DarwinNotificationDetails(); + + var platformChannelSpecifics = NotificationDetails( + android: androidPlatformChannelSpecifics, + iOS: iOSPlatformChannelSpecifics, + ); + + FlutterLocalNotificationsPlugin flip = FlutterLocalNotificationsPlugin(); + await flip.show(0, notification.title, notification.body, platformChannelSpecifics, payload: 'Default_Sound'); + } catch (e) { + debugPrint('error $e'); + } + } + + Future _showNotificationViaFBConsole(RemoteMessage message) async { + final RemoteNotification? notification = message.notification; + if (notification == null) return; + + final String? imgUrl = _getImageUrl(notification); + + debugPrint('==> imgUrl: $imgUrl '); + + BigPictureStyleInformation? styleInformation; + if (imgUrl != null) { + final largeIconPath = await downloadFile(imgUrl, 'largeIcon'); + final bigPicturePath = await downloadFile(imgUrl, 'bigPicture'); + + styleInformation = BigPictureStyleInformation( + FilePathAndroidBitmap(bigPicturePath), + largeIcon: FilePathAndroidBitmap(largeIconPath), + ); + } + + var androidPlatformChannelSpecifics = AndroidNotificationDetails( + channel.id, + channel.name, + icon: '@mipmap/launcher_icon', + channelDescription: channel.description, + // importance: Importance.max, + priority: Priority.high, + // color: ThemeColor.mainColor, + styleInformation: styleInformation, + ); + var iOSPlatformChannelSpecifics = const DarwinNotificationDetails(); + + var platformChannelSpecifics = NotificationDetails( + android: androidPlatformChannelSpecifics, + iOS: iOSPlatformChannelSpecifics, + ); + + flip.initialize( + initSettings, + // onDidReceiveBackgroundNotificationResponse: (details) { + // debugPrint('==> ${details.payload}'); + // }, + onDidReceiveNotificationResponse: (details) { + debugPrint('onDidReceiveNotificationResponse'); + // _performClickAction(message); + }, + ); + await flip.show(0, notification.title, notification.body, platformChannelSpecifics, payload: 'Default_Sound'); + } + + Future _performClickAction(RemoteMessage message) async { + // if (message.data['type'] == 'product') { + // final int productId = int.parse(message.data['id']); + // final ProductModel? model = await ProductApi.getProductById(productId); + // if (model != null) Get.to(() => ProductDetailsPage(model: model)); + // } else if (message.data['type'] == 'filter') { + // message.data.remove('type'); + // navigateToProductListScreen(message.data, false); + // } else { + // open dialog + // if (message.notification == null) return; + + // Get.to( + // () => NotificationPage(title: message.notification!.title ?? '', data: message.notification!.body ?? ''), + // ); + // } + } + + String? _getImageUrl(RemoteNotification notification) { + if (Platform.isIOS && notification.apple != null) return notification.apple?.imageUrl; + if (Platform.isAndroid && notification.android != null) return notification.android?.imageUrl; + return null; + } +} + +final fcmFunctions = FCMFunctions(); + +// backgroundHandler must be on top and separated +Future onBackgroundHandler(RemoteMessage message) async { + // fcmFunctions._showNotification(message); + fcmFunctions._showNotificationViaFBConsole(message); +} + +Future initFCMFunctions() async { + await fcmFunctions.initApp(); + await fcmFunctions.iosWebPermission(); + + FirebaseMessaging.onBackgroundMessage(onBackgroundHandler); + + await fcmFunctions.getFCMToken(); + fcmFunctions.tokenListener(); + fcmFunctions.foreGroundMessageListener(); + await fcmFunctions.subscribeToTopics('notifications'); +} + +/* final http.Response response = await http.get(Uri.parse(URL)); + BigPictureStyleInformation bigPictureStyleInformation = + BigPictureStyleInformation( + ByteArrayAndroidBitmap.fromBase64String(base64Encode(image)), + largeIcon: ByteArrayAndroidBitmap.fromBase64String(base64Encode(image)), + ); + flutterLocalNotificationsPlugin.show( + Random().nextInt(1000), + title, + description, + NotificationDetails( + android: AndroidNotificationDetails(channel.id, channel.name, + channelDescription: channel.description, + importance: Importance.high, + styleInformation: bigPictureStyleInformation), + ), + ); */ diff --git a/lib/core/utils/utils.dart b/lib/core/utils/utils.dart index fd7bd01..297f108 100644 --- a/lib/core/utils/utils.dart +++ b/lib/core/utils/utils.dart @@ -3,3 +3,4 @@ export 'keyboard.dart'; export 'error_util.dart'; export 'http_override.dart'; export 'date_util.dart'; +export 'notification_service.dart'; diff --git a/lib/firebase_options.dart b/lib/firebase_options.dart new file mode 100644 index 0000000..64426b2 --- /dev/null +++ b/lib/firebase_options.dart @@ -0,0 +1,68 @@ +// File generated by FlutterFire CLI. +// ignore_for_file: lines_longer_than_80_chars, avoid_classes_with_only_static_members +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: 'AIzaSyB4aGhjQIDs6neCWrrITI6iujKhKm2Y9cg', + appId: '1:598107454568:android:b2b6e38663f71e9e314fdd', + messagingSenderId: '598107454568', + projectId: 'cargo66', + storageBucket: 'cargo66.appspot.com', + ); + + static const FirebaseOptions ios = FirebaseOptions( + apiKey: 'AIzaSyCMbx3GD8XMCI9vdrQvIy6nTr-kiNx2f9k', + appId: '1:598107454568:ios:3bbcc27922926fe7314fdd', + messagingSenderId: '598107454568', + projectId: 'cargo66', + storageBucket: 'cargo66.appspot.com', + iosBundleId: 'com.example.cargo', + ); +} diff --git a/lib/main.dart b/lib/main.dart index f6c2a88..2650f52 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,10 @@ +import 'dart:developer'; import 'dart:io'; +import 'package:cargo/firebase_options.dart'; import 'package:easy_localization/easy_localization.dart'; +import 'package:firebase_core/firebase_core.dart'; +import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -10,6 +14,21 @@ import 'package:flutter_phoenix/flutter_phoenix.dart'; import 'core/core.dart'; import 'di/di.dart' as di; +Future _initFBInitials() async { + try { + await initFCMFunctions(); + + // await Firebase.initializeApp( + // options: DefaultFirebaseOptions.currentPlatform, + // ); + // final fcmToken = await FirebaseMessaging.instance.getToken(); + // await FirebaseMessaging.instance.setAutoInitEnabled(true); + // log('FCMToken $fcmToken'); + } catch (e) { + debugPrint('FCM error: $e'); + } +} + Future main() async { // WidgetsFlutterBinding.ensureInitialized(); @@ -18,6 +37,8 @@ Future main() async { await EasyLocalization.ensureInitialized(); + _initFBInitials(); + await di.init(); Bloc.observer = MyBlocObserver(); diff --git a/pubspec.lock b/pubspec.lock index 10abb6c..e1c2928 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,6 +1,14 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + _flutterfire_internals: + dependency: transitive + description: + name: _flutterfire_internals + sha256: f5628cd9c92ed11083f425fd1f8f1bc60ecdda458c81d73b143aeda036c35fe7 + url: "https://pub.dev" + source: hosted + version: "1.3.16" another_stepper: dependency: "direct main" description: @@ -129,6 +137,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.10.1" + dbus: + dependency: transitive + description: + name: dbus + sha256: "365c771ac3b0e58845f39ec6deebc76e3276aa9922b0cc60840712094d9047ac" + url: "https://pub.dev" + source: hosted + version: "0.7.10" easy_localization: dependency: "direct main" description: @@ -177,6 +193,54 @@ packages: url: "https://pub.dev" source: hosted version: "7.0.0" + firebase_core: + dependency: "direct main" + description: + name: firebase_core + sha256: "96607c0e829a581c2a483c658f04e8b159964c3bae2730f73297070bc85d40bb" + url: "https://pub.dev" + source: hosted + version: "2.24.2" + firebase_core_platform_interface: + dependency: transitive + description: + name: firebase_core_platform_interface + sha256: f7d7180c7f99babd4b4c517754d41a09a4943a0f7a69b65c894ca5c68ba66315 + url: "https://pub.dev" + source: hosted + version: "5.2.1" + firebase_core_web: + dependency: transitive + description: + name: firebase_core_web + sha256: d585bdf3c656c3f7821ba1bd44da5f13365d22fcecaf5eb75c4295246aaa83c0 + url: "https://pub.dev" + source: hosted + version: "2.10.0" + firebase_messaging: + dependency: "direct main" + description: + name: firebase_messaging + sha256: "980259425fa5e2afc03e533f33723335731d21a56fd255611083bceebf4373a8" + url: "https://pub.dev" + source: hosted + version: "14.7.10" + firebase_messaging_platform_interface: + dependency: transitive + description: + name: firebase_messaging_platform_interface + sha256: "54e283a0e41d81d854636ad0dad73066adc53407a60a7c3189c9656e2f1b6107" + url: "https://pub.dev" + source: hosted + version: "4.5.18" + firebase_messaging_web: + dependency: transitive + description: + name: firebase_messaging_web + sha256: "90dc7ed885e90a24bb0e56d661d4d2b5f84429697fd2cbb9e5890a0ca370e6f4" + url: "https://pub.dev" + source: hosted + version: "3.5.18" flutter: dependency: "direct main" description: flutter @@ -206,6 +270,30 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.2" + flutter_local_notifications: + dependency: "direct main" + description: + name: flutter_local_notifications + sha256: c500d5d9e7e553f06b61877ca6b9c8b92c570a4c8db371038702e8ce57f8a50f + url: "https://pub.dev" + source: hosted + version: "17.2.2" + flutter_local_notifications_linux: + dependency: transitive + description: + name: flutter_local_notifications_linux + sha256: c49bd06165cad9beeb79090b18cd1eb0296f4bf4b23b84426e37dd7c027fc3af + url: "https://pub.dev" + source: hosted + version: "4.0.1" + flutter_local_notifications_platform_interface: + dependency: transitive + description: + name: flutter_local_notifications_platform_interface + sha256: "85f8d07fe708c1bdcf45037f2c0109753b26ae077e9d9e899d55971711a4ea66" + url: "https://pub.dev" + source: hosted + version: "7.2.0" flutter_localizations: dependency: transitive description: flutter @@ -309,6 +397,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.19.0" + js: + dependency: transitive + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" json_annotation: dependency: transitive description: @@ -429,6 +525,30 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.1" + path_provider: + dependency: "direct main" + description: + name: path_provider + sha256: fec0d61223fba3154d87759e3cc27fe2c8dc498f6386c6d6fc80d1afdd1bf378 + url: "https://pub.dev" + source: hosted + version: "2.1.4" + path_provider_android: + dependency: transitive + description: + name: path_provider_android + sha256: "6f01f8e37ec30b07bc424b4deabac37cacb1bc7e2e515ad74486039918a37eb7" + url: "https://pub.dev" + source: hosted + version: "2.2.10" + path_provider_foundation: + dependency: transitive + description: + name: path_provider_foundation + sha256: f234384a3fdd67f989b4d54a5d73ca2a6c422fa55ae694381ae0f4375cd1ea16 + url: "https://pub.dev" + source: hosted + version: "2.4.0" path_provider_linux: dependency: transitive description: @@ -453,6 +573,54 @@ packages: url: "https://pub.dev" source: hosted version: "2.3.0" + permission_handler: + dependency: "direct main" + description: + name: permission_handler + sha256: "18bf33f7fefbd812f37e72091a15575e72d5318854877e0e4035a24ac1113ecb" + url: "https://pub.dev" + source: hosted + version: "11.3.1" + permission_handler_android: + dependency: transitive + description: + name: permission_handler_android + sha256: "76e4ab092c1b240d31177bb64d2b0bea43f43d0e23541ec866151b9f7b2490fa" + url: "https://pub.dev" + source: hosted + version: "12.0.12" + permission_handler_apple: + dependency: transitive + description: + name: permission_handler_apple + sha256: e6f6d73b12438ef13e648c4ae56bd106ec60d17e90a59c4545db6781229082a0 + url: "https://pub.dev" + source: hosted + version: "9.4.5" + permission_handler_html: + dependency: transitive + description: + name: permission_handler_html + sha256: af26edbbb1f2674af65a8f4b56e1a6f526156bc273d0e65dd8075fab51c78851 + url: "https://pub.dev" + source: hosted + version: "0.1.3+2" + permission_handler_platform_interface: + dependency: transitive + description: + name: permission_handler_platform_interface + sha256: fe0ffe274d665be8e34f9c59705441a7d248edebbe5d9e3ec2665f88b79358ea + url: "https://pub.dev" + source: hosted + version: "4.2.2" + permission_handler_windows: + dependency: transitive + description: + name: permission_handler_windows + sha256: "1a790728016f79a41216d88672dbc5df30e686e811ad4e698bfc51f76ad91f1e" + url: "https://pub.dev" + source: hosted + version: "0.2.1" petitparser: dependency: transitive description: @@ -610,6 +778,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.7.0" + timezone: + dependency: transitive + description: + name: timezone + sha256: "2236ec079a174ce07434e89fcd3fcda430025eb7692244139a9cf54fdcf1fc7d" + url: "https://pub.dev" + source: hosted + version: "0.9.4" typed_data: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index cdbe00c..071cb2e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -31,6 +31,11 @@ dependencies: flutter_native_splash: ^2.4.1 url_launcher: ^6.3.0 another_stepper: ^1.2.2 + firebase_messaging: ^14.7.10 + firebase_core: ^2.24.2 + flutter_local_notifications: ^17.2.2 + path_provider: ^2.1.4 + permission_handler: ^11.3.1 dev_dependencies: flutter_test: