'Detecting flutter app opened from a terminated state with FCM and flutter_local_notifications
I am working on a flutter app that uses FCM data messages sent through cloud functions. In my app I'm receiving that data messages and then displaying a local notification. I need to be able to tap the local notification and have it direct the user to the correct screen. My current solution works when the app is in the foreground, or background, but NOT terminated. When it's terminated tapping on the notification appears to just open the app. Is there a way to detect if the app just opened from a terminated state? Below is my current code for when the notification is tapped, and the comments show what I want it to do
Future onSelectNotification(String payload) async {
Map data = json.decode(payload);
print('onSelectNotification: $data');
// if app is in foreground or background do this
if (data.containsKey('conversation_with')) {
print('Notification was for a conversation');
String conversationID = data['conversation_with'];
print('Conversation with UID: $conversationID');
PublicAppUser conversationWith =
await FriendDatabase().getPublicAppUser(conversationID);
navigatorKey.currentState!.pushNamed(
ConversationPublicUserScreen.routeName,
arguments: conversationWith);
}
// if it just opened from a terminated state do this
// ...
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
