Skip to content

Commit

Permalink
Notification Related Implementation Removed
Browse files Browse the repository at this point in the history
  • Loading branch information
andoriyaprashant committed Nov 7, 2023
1 parent 2d73c3b commit 3403461
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 83 deletions.
118 changes: 59 additions & 59 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ late Map<String, dynamic> androidFirebaseOptions;
late Map<String, dynamic> 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.
///
Expand All @@ -81,25 +81,25 @@ Future<void> 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
Expand All @@ -120,7 +120,7 @@ Future<void> main() async {
await setUpFirebaseKeys();

await setUpFirebase();
await setUpFirebaseMessaging();
// await setUpFirebaseMessaging();
}
} catch (e) {
print("Firebase not working");
Expand Down Expand Up @@ -337,40 +337,40 @@ class DemoViewModel extends BaseModel {
///
/// **returns**:
/// * `Future<void>`: promise that will be fulfilled Firebase is setted up.
Future<void> 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<void> 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) {});
// }
51 changes: 27 additions & 24 deletions test/helpers/setup_firebase_mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,30 +156,33 @@ class MockFirebaseMessaging extends Mock
);
}

@override
Future<NotificationSettings> 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<NotificationSettings>(),
returnValueForMissingStub: neverEndingFuture<NotificationSettings>(),
);
}
// Comment out the notification logic for the MVP
// TODO: Re-enable notifications when needed for the final release.

// @override
// Future<NotificationSettings> 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<NotificationSettings>(),
// returnValueForMissingStub: neverEndingFuture<NotificationSettings>(),
// );
// }

@override
Future<void> subscribeToTopic(String? topic) {
Expand Down

0 comments on commit 3403461

Please sign in to comment.