@@ -37,6 +37,11 @@ class NotificationManager {
37
37
}
38
38
}
39
39
40
+ // Returns the remote notification only when the app is opened from terminated state otherwise it'll be null
41
+ Future <RemoteMessage ?> getInitialMessage () {
42
+ return FirebaseMessaging .instance.getInitialMessage ();
43
+ }
44
+
40
45
/// get the device token. This guarantees the token (if available)
41
46
/// is the latest correct token
42
47
Future <String ?> getDeviceToken () async {
@@ -101,8 +106,8 @@ class NotificationManager {
101
106
}
102
107
103
108
void initGetInitialMessage () {
104
- // This is called when the user taps on the notification and the app is opened from the terminated state
105
- FirebaseMessaging .instance. getInitialMessage ().then ((message) {
109
+ // Returns the remote notification only when the app is opened from the terminated state or else it'll be null
110
+ getInitialMessage ().then ((message) {
106
111
if (message == null ) return ;
107
112
108
113
Ensemble .externalDataContext.addAll ({
@@ -120,17 +125,15 @@ class NotificationManager {
120
125
121
126
Future <void > _handleNotification () async {
122
127
Map <String , dynamic >? messageData = Ensemble .externalDataContext['data' ];
123
- if (messageData? ['screenId' ] != null ||
124
- messageData? ['screenName' ] != null ) {
125
- ScreenController ().navigateToScreen (
126
- Utils .globalAppKey.currentContext! ,
128
+ // If there is a screen, it navigates to that page
129
+ // or else it'll open the app with the root screen and clears all the previous screens
130
+ final screenNotFound =
131
+ messageData? ['screenId' ] == null && messageData? ['screenName' ] == null ;
132
+ ScreenController ().navigateToScreen (Utils .globalAppKey.currentContext! ,
127
133
screenId: messageData! ['screenId' ],
128
134
screenName: messageData['screenName' ],
129
135
pageArgs: messageData,
130
- );
131
- } else {
132
- log ('No screenId nor screenName provided on the notification. Ignoring ...' );
133
- }
136
+ routeOption: screenNotFound ? RouteOption .clearAllScreens : null );
134
137
}
135
138
}
136
139
0 commit comments