当前,onMessage函数将显示AlertDialog。此功能运行良好。
不过,当应用程序在前台时,我想显示一个小吃条。
有人有这样的例子吗?
我当前的initState:
void initState() {
super.initState();
getCurrentUser();
extractMachineIDs(); //IGNORE
getMachineStatus(0); //IGNORE
_fcm.configure(
onMessage: (Map<String, dynamic> message) async {
print("onMessage: $message");
showDialog( // I WANT A SNACKBAR HERE INSTEAD
context: context,
builder: (context) => AlertDialog(
content: ListTile(
title: Text(message['notification']['title']),
subtitle: Text(message['notification']['body']),
),
actions: <Widget>[
FlatButton(
child: Text('DISMISS'),
onPressed: () => Navigator.of(context).pop(),
),
],
),
);
},
onLaunch: (Map<String, dynamic> message) async {
print("onLaunch: $message");
},
onResume: (Map<String, dynamic> message) async {
print("onResume: $message");
Navigator.pushNamed(context, AlertsNotifications.id);
},
);
}
使用此而不是showDialog
:
final snackBar = SnackBar(
content: Text('Yay! A SnackBar!'),
action: SnackBarAction(
label: 'Some Text',
onPressed: () {
// Some code.
},
),
);
Scaffold.of(context).showSnackBar(snackBar);