我正在使用showNotificationAtScheduleCron
Awesome 通知包。它给了我计划创建但是当特定时间到来时没有通知并且也给我这个 [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Bad state: Stream has already been listened to.
我想在特定时间发出通知并删除此错误。
@override
_LocalNotificationScreenState createState() => _LocalNotificationScreenState();
}
class _LocalNotificationScreenState extends State<LocalNotificationScreen > {
@override
void initState(){
super.initState();
AwesomeNotifications().isNotificationAllowed().then((isAllowed) {
if (!isAllowed) {
AwesomeNotifications().requestPermissionToSendNotifications();
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('notify'),
),
body: Center(
child: TextButton(
onPressed:()async{
// await notification.delayNotification(0);
//await notification.showBigPictureNotificationActionButtons(0);
await notification.showNotificationAtScheduleCron(0, "title", 'body', DateTime(2021,7,19,12,10));
AwesomeNotifications().displayedStream.listen((receivedNotification) {
FlutterRingtonePlayer.playNotification(looping: true,asAlarm: true);
});
AwesomeNotifications().actionStream.listen((event) {
if(event.buttonKeyPressed =='cancel')
FlutterRingtonePlayer.stop();
if (event.buttonKeyPressed=='snooze') {
FlutterRingtonePlayer.stop();
notification.delayNotification(0,"title", "body");
}
});
} ,
child: Text('SendNotification') ,
),
),
);
}
}