i got _configureSelectNotificationSubject configured but, where i call this function, because that never calls the screen when i push the notification, never open the screen configured!
im using flutter_local_notifications 19.1.0
ok i know now this function its called:
void _configureSelectNotificationSubject() {
print (“################### call it”);
selectNotificationStream.stream
.listen((NotificationResponse? response) async {
print (“################### dont call it”);
await Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) =>
NotificacoesHomeScreen(usuario: usuario, payload: response?.payload, data: response?.data),
));
});
}
selectNotificationStream.stream
.listen((NotificationResponse? response) async {
dont enter here, why? selectNotificationStream.stream dont works???
I use that package, look at the _checknotification function in snag/lib/snag.dart at main · mihalycsaba/snag · GitHub
You probably will need some router package, doing it my way will mess up hot reload(restarts the app instead hot reloading). I’m planning to fix it, just didn’t get around to doing it.
1 Like
ok i will see, i got the routs configured in main.dart
runApp(
MaterialApp(
initialRoute: initialRoute,
routes: <String, WidgetBuilder>{
LandingScreen.routeName: () => LandingScreen(notificationAppLaunchDetails: notificationAppLaunchDetails, emailId: usuario.email.toString(),),
NotificacoesHomeScreen.routeName: () => NotificacoesHomeScreen(usuario: usuario, payload: selectedNotificationPayload,)
},
),
);
Just remembered, that function is only for when the app is not running and you are starting the app from a notification.
If the app is already running it goes through this function snag/lib/views/notifications/initialize_notifications.dart at main · mihalycsaba/snag · GitHub
I don’t know if this is the best way of doing it, but it works seemingly without problems. It doesn’t seem to slow down the page load.
1 Like
there’s this function that returns the route based on the id from the notification notificationDestination(id);
1 Like
ok, i understand that app have be closed to push the notification, i will see your exemples, try to interact your code with my! but to show notifications its the same! tks for yet!
initialize notifications its the same too, i already have this code include in main.dart
It doesn’t have to be closed to get a notification. You probably just missing the part to check the notification when the app is stopped.
Keep in mind, since it relies on an async function it will break hot reload if you get it in the build function, like me. It works by setting the initial route to the notification destination. The routes have to be configured before the build function runs, to keep hot reload. It’s fixable, it’s just not that important for me.
ok i understand, i will try to set the routes like yours
I would like to see how you use that, I put my initalize_notification in some of the higher routes’s build method, but I’m not sure if it’s the best way.
So, i look to your code, and i have to change too much im my code, so i discovery another way and ease to open direct to the screen i want no needs even routes:
just put this code in first page, and works well:
_getAppLaunchDetails() async {
var details = await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails();
if (details!.didNotificationLaunchApp) {
if (details.notificationResponse?.payload == “/notificacoes”) {
await Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) =>
NotificacoesHomeScreen(usuario: usuario),
));
}
}
}
call it in init _getAppLaunchDetails();
if u want someone data to send:
you can get details.notificationResponse?.data
finally, i way ease to works!
thanks, any way!
it’s the same thing, maybe I could do this before runapp in main, maybe that way the app would maybe survive hot reload and I won’t need a futurebuilder
1 Like