Last active
April 28, 2023 07:18
-
-
Save harunme3/189db342c9de383d1f45a386b61a60e9 to your computer and use it in GitHub Desktop.
How to integrate push notification using one signal in flutter
This file contains 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
## step 1 - add intent in AndroidManifest.xml file | |
<intent-filter> | |
<action android:name="FLUTTER_NOTIFICATION_CLICK" /> | |
<category android:name="android.intent.category.DEFAULT" /> | |
</intent-filter> | |
## step 2 - add this in main.dart file in main function | |
WidgetsFlutterBinding.ensureInitialized(); | |
await OneSignal.shared.setAppId(appid); | |
OneSignal.shared.setNotificationWillShowInForegroundHandler( | |
(OSNotificationReceivedEvent event) { | |
// Will be called whenever a notification is received in foreground | |
// Display Notification, pass null param for not displaying the notification | |
Logger().w(event.notification); | |
Logger().e(event.notification.rawPayload); | |
event.complete(event.notification); | |
}, | |
); | |
## step 3 - add this in dashboard.dart file in initstate function | |
OneSignal.shared.setNotificationOpenedHandler( | |
(OSNotificationOpenedResult result) { | |
// Will be called whenever a notification is opened/button pressed. | |
Logger().w(result.notification.additionalData); | |
String path = result.notification.additionalData!['key1']; | |
Logger().e(path); | |
Get.toNamed( | |
'/$path', | |
); | |
}, | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment