Hi,
I am using flutter_bloc in my application and for notifications, I am using https://pub.dev/packages/firebase_messaging. I am in need of redirecting the user to a specific screen in the application when a notification is received via onResume() or onLauch() method in the main.dart. How to do this?
When tried with Navigator, page redirection is not happening. I am following https://github.com/felangel/bloc/tree/master/examples/flutter_login for this.
Please help me to resolve this issue.
Thanks.
@karthikeyanp307 Can you share your project or some code with where the issue is happening.
It would seem like your bloc isn't high enough in the tree to catch when a notification comes in to yield a new state OR that your state isn't changing correctly and so the Navigation code isn't being called.
Of course, it could be neither of these things.
HI @karthikeyanp307 馃憢
Thanks for opening an issue!
As @warriorCoder mentioned, it would be much easier to help if you could share a sample app which illustrates the problem you're facing 馃憤
Hi @felangel ,
Thanks for your reply and comments. I have shared a sample code via https://github.com/karthikeyanp307/flutter_login. This is not an executable one but for your view. Please help me to redirect to the inbox page from main.dart.
Thanks in advance.
@karthikeyanp307 To do this, you need to do something like the following in initState():
_firebaseMessaging.configure(onResume:
(Map
print("onResume: $message");
print(notificationBloc.state.toString());
notificationBloc.add(
NotificationReceived(
my.Notification(
id: uuid.v5(Uuid.NAMESPACE_URL, 'www.example.com'),
title: message['notification']['title'],
body: message['notification']['body']),
),
);
},
);
Then to redirect your page, you need to listen to the bloc state with a bloc consumer in your navigation element.
To recap ->
@mintymac thanks so much for taking the time to answer, I really appreciate it!
@karthikeyanp307 closing this for now but feel free to comment with any additional questions and I鈥檓 happy to continue the conversation 馃憤
Most helpful comment
@mintymac thanks so much for taking the time to answer, I really appreciate it!
@karthikeyanp307 closing this for now but feel free to comment with any additional questions and I鈥檓 happy to continue the conversation 馃憤