В моем приложении я настроил уведомление firebase pu sh, и у меня есть код конфигурации следующим образом. Он показывает onMessage на странице, где я реализовал этот код в initState
. У меня есть многостраничные поля формы в приложении, и я хочу, чтобы оповещение отображалось на любой странице приложения. Есть ли способ показать предупреждение на каждом экране, не вызывая функцию в initState
на каждой странице?
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
showDialog(
context: context,
builder: (context) => AlertDialog(
content: ListTile(
title: Text(message['notification']['title']),
subtitle: Text(message['notification']['body']),
),
actions: <Widget>[
FlatButton(
child: Text('Ok'),
onPressed: () => Navigator.of(context).pop(),
),
],
),
);
print("onMessage: $message");
final notification = message['notification'];
setState(() {
messages.add(Message(
title: notification['title'], body: notification['body']));
});
},
onLaunch: (Map<String, dynamic> message) async {
print("onLaunch: $message");
final notification = message['data'];
setState(
() {
messages.add(
Message(
title: '${notification['title']}',
body: '${notification['body']}',
),
);
},
);
Navigator.pushNamed(context, '/notify');
},