'How to redirect to a specific screen after main.dart upon reopening app from foreground?
I have a Flutter application with push notifications through flutter_local_notifications. When the app is open, I press the "Home" button on the iPhone 12 emulator. Then, when a push notification is pressed, I can see what the payload of said notification is in main.dart with a listener:
await flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: (String? payload) async {
if (payload != null) {
debugPrint('notification payload: $payload');
}
});
What I'm trying to do is redirect to a specific screen if the payload (String) is equal to a specific value like so:
await flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: (String? payload) async {
if (payload != null) {
debugPrint('notification payload: $payload');
}
if (payload == "test") {
// navigate to test screen instead of home screen
}
});
One of the issues I'm seeing is that "context" is unavailable, even after importing dependency. Is this functionality possible?
Solution 1:[1]
Alternatively, you could use a flutter dynamic links
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | THEODORE |
