如何解决在颤振中设置几个预定的通知不起作用
我将 id 更改为随机生成的数字,但在我安排一个通知然后另一个通知后,第一个不会显示。
(由于其他版本问题,我需要这些旧版本)
Flutter_local_notifications:^1.4.4+4
rxdart:^0.24.1
这是触发器:
Padding(
padding: const EdgeInsets.all(8.0),child: Container(
decoration: Boxdecoration(
color:
colorChangeNotifyButton ? Colors.grey : Colors.blue,borderRadius: BorderRadius.circular(15)),child: MaterialButton(
child: Text("Notify me"),onpressed: () {
setState(() =>
colorChangeNotifyButton = !colorChangeNotifyButton);
}),),],Padding(
padding: const EdgeInsets.all(8.0),child: Container(
decoration: Boxdecoration(
color: Colors.blue,child: MaterialButton(
child: Text("Submit"),onpressed: () async {
try {
if (task == null || task.length < 2) {
error(context,"Please add content");
} else {
colorChangeNotifyButton
? null
: await localNotifiyManager.scheduleNotification(
selectedTime,'Reminder:',task,rng.nextInt(100000),rng.nextInt(100000).toString()
);
print(colorChangeNotifyButton.toString());
setState(() => colorChangeNotifyButton = true);
print('test');
print(colorChangeNotifyButton.toString());
}
} catch (e) {
error(context,e);
}
这是我的 LocalNotifyManager.dart:
import 'package:Flutter/material.dart';
import 'package:Flutter_local_notifications/Flutter_local_notifications.dart';
import 'dart:io' show Platform;
import 'package:rxdart/subjects.dart';
class LocalNotifyManager {
FlutterlocalnotificationsPlugin FlutterlocalnotificationsPlugin;
var initSetting;
BehaviorSubject<Receivednotification>
get DidReceivelocalnotificationSubject =>
BehaviorSubject<Receivednotification>();
LocalNotifyManager.init() {
FlutterlocalnotificationsPlugin = FlutterlocalnotificationsPlugin();
if (Platform.isIOS) {
requestIOSPermission();
}
initializePlatform();
}
requestIOSPermission() {
FlutterlocalnotificationsPlugin
.resolvePlatformSpecificImplementation<
IOSFlutterlocalnotificationsPlugin>()
.requestPermissions(alert: true,badge: true,sound: true);
}
initializePlatform() {
//Todo: need to fix with implementing Notifications for android
var initSettingAndroid = AndroidInitializationSettings('100.png');
var initSettingIOS = IOSInitializationSettings(
requestSoundPermission: true,requestAlertPermission: true,requestBadgePermission: true,onDidReceivelocalnotification: (id,title,body,payload) async {
Receivednotification notification = Receivednotification(
id: id,title: title,body: body,payload: payload);
DidReceivelocalnotificationSubject.add(notification);
});
initSetting = InitializationSettings(initSettingAndroid,initSettingIOS);
}
setonNotificationReceive(Function onNotificationReceive) {
DidReceivelocalnotificationSubject.listen((notification) {
onNotificationReceive(notification);
});
}
setonNotificationClick(Function onNotificationClick) async {
await FlutterlocalnotificationsPlugin.initialize(initSetting,onSelectNotification: (String payload) async {
onNotificationClick(payload);
});
}
Future<void> scheduleNotification(DateTime scheduleNotificationDateTime,String title,String body,int id,String payload) async {
var androidChannel = AndroidNotificationDetails(
'CHANNEL_ID','CHANNEL_NAME','CHANNEL_DESCRIPTION',importance: Importance.Max,priority: Priority.High,playSound: true);
var iosChannel = IOSNotificationDetails();
var platformChannel = NotificationDetails(androidChannel,iosChannel);
await FlutterlocalnotificationsPlugin.schedule(
id,scheduleNotificationDateTime,platformChannel,payload: payload);
}
}
LocalNotifyManager localNotifiyManager = LocalNotifyManager.init();
class Receivednotification {
Receivednotification({
@required this.id,@required this.title,@required this.body,@required this.payload,});
final int id;
final String title;
final String body;
final String payload;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。