我正在使用Firebase消息服务,并且试图将创建的任务通知自己。例如,我已将任务设置为1月6日,并且我希望该应用在1月6日通知我。我不了解如何执行此操作,因为我刚开始使用flutter(飞镖)。
在这里,我尝试过这样的代码,我已经完整列出了来自Firebase Cloud Firestore的任务,但是我想在上面添加通知服务。
这是我的代码。
@override
void initState() {
// TODO: implement initState
super.initState();
_dateText = "${_dueDate.day}/${_dueDate.month}/${_dueDate.year}";
menuDataList = [
new MenuData(Icons.add, (context, menuData) {
// Navigator.of(context).push(new MaterialPageRoute(builder: (BuildContext context)=> new AddTask(email: widget.user.email)));
_addData();
}
,labelText: 'Add Task'
),
new MenuData(Icons.group_add, (context, menuData) {
Navigator.of(context).push(new MaterialPageRoute(builder: (BuildContext context)=> new AddGroup(email: widget.user.email)));
}
,labelText: 'Add Group'
),
new MenuData(Icons.group, (context, menuData) {
Navigator.of(context).push(new MaterialPageRoute(builder: (BuildContext context)=> new CreateGroup(email: widget.user.email )));
}
,labelText: 'View Group'
),
new MenuData(Icons.search, (context, menuData) {
Navigator.of(context).push(new MaterialPageRoute(builder: (BuildContext context)=> new MySearchPage()));
}
,labelText: 'Search Here'
),
];
var android = new AndroidInitializationSettings('mipmap/ic_launcher');
var ios = new IOSInitializationSettings();
var platform = new InitializationSettings(android , ios);
flutterLocalNotificationsPlugin.initialize(platform);
_firebaseMessaging.configure(
onMessage: (Map<String , dynamic> message){
showNotification(message);
print('on message $message');
},
onResume: (Map<String , dynamic> message){
showNotification(message);
print('on message $message');
},
onLaunch: (Map<String , dynamic> message){
showNotification(message);
print('on message $message');
},
);
_firebaseMessaging.getToken().then((token){
print(token);
});
}
showNotification(Map<String , dynamic> message) async{
var android = new AndroidNotificationDetails('channel_id' , "CHANNAL NAME" , "channelDescription");
var ios = IOSNotificationDetails();
var platform = new NotificationDetails(android, ios);
await flutterLocalNotificationsPlugin.show(0, "this is my title", "this is my body title", platform);
}