Created
April 5, 2022 14:04
-
-
Save OmarYehiaDev/c7c2cbcca982650736fb4a18778eb9f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<void> openOffersPage(RemoteMessage? message) async { | |
if (message != null) { | |
if (message.data['type'] == 'offers') { | |
Navigator.push( | |
key.currentContext!, | |
MaterialPageRoute( | |
builder: (_) => HotOffers(), | |
), | |
); | |
} | |
} | |
await messaging.getInitialMessage().then((msg) { | |
if (msg!.data['type'] == 'offers') { | |
Navigator.push( | |
key.currentContext!, | |
MaterialPageRoute( | |
builder: (_) => HotOffers(), | |
), | |
); | |
} | |
}); | |
} | |
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async { | |
await flutterLocalNotificationsPlugin | |
.resolvePlatformSpecificImplementation< | |
AndroidFlutterLocalNotificationsPlugin>() | |
?.createNotificationChannel(channel); | |
await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions( | |
alert: true, // Required to display a heads up notification | |
badge: true, | |
sound: true, | |
); | |
RemoteNotification? notification = message.notification; | |
AndroidNotification? android = message.notification?.android; | |
// If `onMessage` is triggered with a notification, construct our own | |
// local notification to show to users using the created channel. | |
if (notification != null && android != null) { | |
await openOffersPage(message); | |
flutterLocalNotificationsPlugin.show( | |
notification.hashCode, | |
notification.title, | |
notification.body, | |
NotificationDetails( | |
android: AndroidNotificationDetails( | |
channel.id, | |
channel.name, | |
channelDescription: channel.description, | |
icon: 'notification', | |
), | |
), | |
payload: "offers", | |
); | |
} | |
print("Handling a background message: ${message.messageId}"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment