From 3403461988405a90950e0caeba1234f3249d3536 Mon Sep 17 00:00:00 2001 From: andoriyaprashant Date: Tue, 7 Nov 2023 11:27:36 +0530 Subject: [PATCH] Notification Related Implementation Removed --- lib/main.dart | 118 ++++++++++++------------- test/helpers/setup_firebase_mocks.dart | 51 ++++++----- 2 files changed, 86 insertions(+), 83 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 19350a4cc..fb39525c3 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -65,10 +65,10 @@ late Map androidFirebaseOptions; late Map iosFirebaseOptions; /// Create a [AndroidNotificationChannel] for heads up notifications. -late AndroidNotificationChannel channel; +/// late AndroidNotificationChannel channel; /// Initialize the [FlutterLocalNotificationsPlugin] package. -late FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin; +/// late FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin; /// First function to initialize the application, invoked automatically. /// @@ -81,25 +81,25 @@ Future main() async { // Returns an instance of the binding that implements WidgetsBinding. WidgetsFlutterBinding.ensureInitialized(); - if (!kIsWeb) { - channel = const AndroidNotificationChannel( - 'high_importance_channel', // id - 'High Importance Notifications', // title - description: - 'This channel is used for important notifications.', // description - 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< - AndroidFlutterLocalNotificationsPlugin>() - ?.createNotificationChannel(channel); - } + // if (!kIsWeb) { + // channel = const AndroidNotificationChannel( + // 'high_importance_channel', // id + // 'High Importance Notifications', // title + // description: + // 'This channel is used for important notifications.', // description + // 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< + // AndroidFlutterLocalNotificationsPlugin>() + // ?.createNotificationChannel(channel); + // } final Directory dir = await path.getApplicationDocumentsDirectory(); Hive @@ -120,7 +120,7 @@ Future main() async { await setUpFirebaseKeys(); await setUpFirebase(); - await setUpFirebaseMessaging(); + // await setUpFirebaseMessaging(); } } catch (e) { print("Firebase not working"); @@ -337,40 +337,40 @@ class DemoViewModel extends BaseModel { /// /// **returns**: /// * `Future`: promise that will be fulfilled Firebase is setted up. -Future setUpFirebaseMessaging() async { - /// Set the background messaging handler early on, as a named top-level function - FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler); - - // Update the iOS foreground notification presentation options to allow heads up notifications. - await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions( - alert: true, - badge: true, - sound: true, - ); - - FirebaseMessaging.instance - .getInitialMessage() - .then((RemoteMessage? message) {}); - - FirebaseMessaging.onMessage.listen((RemoteMessage message) { - final RemoteNotification? notification = message.notification; - final AndroidNotification? android = message.notification?.android; - if (notification != null && android != null && !kIsWeb) { - flutterLocalNotificationsPlugin.show( - notification.hashCode, - notification.title, - notification.body, - NotificationDetails( - android: AndroidNotificationDetails( - channel.id, - channel.name, - channelDescription: channel.description, - icon: 'launch_background', - ), - ), - ); - } - }); - - FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {}); -} +// Future setUpFirebaseMessaging() async { +// /// Set the background messaging handler early on, as a named top-level function +// FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler); + +// // Update the iOS foreground notification presentation options to allow heads up notifications. +// await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions( +// alert: true, +// badge: true, +// sound: true, +// ); + + // FirebaseMessaging.instance + // .getInitialMessage() + // .then((RemoteMessage? message) {}); + + // FirebaseMessaging.onMessage.listen((RemoteMessage message) { + // final RemoteNotification? notification = message.notification; + // final AndroidNotification? android = message.notification?.android; + // if (notification != null && android != null && !kIsWeb) { + // flutterLocalNotificationsPlugin.show( + // notification.hashCode, + // notification.title, + // notification.body, + // NotificationDetails( + // android: AndroidNotificationDetails( + // channel.id, + // channel.name, + // channelDescription: channel.description, + // icon: 'launch_background', + // ), + // ), + // ); + // } + // }); + +// FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {}); +// } diff --git a/test/helpers/setup_firebase_mocks.dart b/test/helpers/setup_firebase_mocks.dart index 57bfaae23..622f975ac 100644 --- a/test/helpers/setup_firebase_mocks.dart +++ b/test/helpers/setup_firebase_mocks.dart @@ -156,30 +156,33 @@ class MockFirebaseMessaging extends Mock ); } - @override - Future requestPermission({ - bool? alert = true, - bool? announcement = false, - bool? badge = true, - bool? carPlay = false, - bool? criticalAlert = false, - bool? provisional = false, - bool? sound = true, - }) { - return super.noSuchMethod( - Invocation.method(#requestPermission, [], { - #alert: alert, - #announcement: announcement, - #badge: badge, - #carPlay: carPlay, - #criticalAlert: criticalAlert, - #provisional: provisional, - #sound: sound, - }), - returnValue: neverEndingFuture(), - returnValueForMissingStub: neverEndingFuture(), - ); - } +// Comment out the notification logic for the MVP +// TODO: Re-enable notifications when needed for the final release. + + // @override + // Future requestPermission({ + // bool? alert = true, + // bool? announcement = false, + // bool? badge = true, + // bool? carPlay = false, + // bool? criticalAlert = false, + // bool? provisional = false, + // bool? sound = true, + // }) { + // return super.noSuchMethod( + // Invocation.method(#requestPermission, [], { + // #alert: alert, + // #announcement: announcement, + // #badge: badge, + // #carPlay: carPlay, + // #criticalAlert: criticalAlert, + // #provisional: provisional, + // #sound: sound, + // }), + // returnValue: neverEndingFuture(), + // returnValueForMissingStub: neverEndingFuture(), + // ); + // } @override Future subscribeToTopic(String? topic) {