Showing push notification on any screen

125 views
Skip to first unread message

Angela Scott

unread,
May 15, 2020, 5:00:58 AM5/15/20
to Flutter Development (flutter-dev)
Hi

I have a flutter project and I am able to receive notifications the only problem I have is when the app is open I need to be on the notification screen to see that a notification has came through.




I have a dialog box that shows the notification but I was wondering how can I put it so its on any screen that the user is using 


Graham Dickinson

unread,
May 15, 2020, 5:58:02 AM5/15/20
to Flutter Development (flutter-dev)


On Friday, 15 May 2020 11:00:58 UTC+2, Angela Scott wrote:
What does your page tree look like and where are you initialising FCM and calling Firebase messaging configure?

Angela Scott

unread,
May 15, 2020, 6:00:18 AM5/15/20
to Flutter Development (flutter-dev)

_messaging.requestNotificationPermissions(
const IosNotificationSettings(
sound: true, badge: true, alert: true, provisional: false));

_messaging.onIosSettingsRegistered
.listen((IosNotificationSettings settings) {
print("Settings registered: $settings");
});

_messaging.getToken().then((String token) {
print("token: $token");
});
}


_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print("onMessage: $message");
final notification = message['notification'];
setState(() {
messages.add(Message(
title: notification['title'], body: notification['body']));
});
final snackbar = SnackBar(
content: Text(message['notification']['title']),
action: SnackBarAction(
label: 'Go',
onPressed: () => null,
),
);

Scaffold.of(context).showSnackBar(snackbar);
showDialog(
context: context,
builder: (context) => AlertDialog(
content: ListTile(
title: Text(message['notification']['title']),
subtitle: Text(message['notification']['body']),
),
actions: <Widget>[
FlatButton(
color: Colors.amber,
child: Text('Ok'),
onPressed: () => Navigator.of(context).pop(),
),
],
),
);
},

Graham Dickinson

unread,
May 15, 2020, 6:04:41 AM5/15/20
to Flutter Development (flutter-dev)
Yes, but where in your app page (screen) tree are you calling these eg. in your home page or your notification screen?
Reply all
Reply to author
Forward
0 new messages