Как я могу запустить несколько уведомлений на флаттер с указанным временем для каждого? - PullRequest
0 голосов
/ 13 апреля 2020

Я использую уведомления, которые повторяются каждый час с разными идентификаторами и каналами, но я получил только первый раз evert и другие заблокированные, а иногда и только laston.

это моя функция уведомлений

Future<void> _scheduleNotification(id,duration,channelname,channelid,soundandroid,soundios,message,title) async {

   var vibrationPattern = Int64List(4);
   vibrationPattern[0] = 0;
   vibrationPattern[1] = 1000;
   vibrationPattern[2] = 5000;
   vibrationPattern[3] = 2000;
 var androidPlatformChannelSpecifics = AndroidNotificationDetails(
       channelid,
       channelname,
       'your other channel description',
       icon: '@mipmap/ic_launcher',
       importance: Importance.Max,
       priority: Priority.High,
       ongoing: true,
       autoCancel: false,
       sound: RawResourceAndroidNotificationSound(soundandroid),
       largeIcon: DrawableResourceAndroidBitmap('@mipmap/ic_launcher'),
       vibrationPattern: vibrationPattern,
       enableLights: true,
       color: const Color.fromARGB(255, 255, 0, 0),
       ledColor: const Color.fromARGB(255, 255, 0, 0),
       ledOnMs: 1000,
       ledOffMs: 500);
   var iOSPlatformChannelSpecifics =
       IOSNotificationDetails(sound:soundios);
   var platformChannelSpecifics = NotificationDetails(
       androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
   await flutterLocalNotificationsPlugin.periodicallyShow(
       id,
       title,
       message,
       RepeatInterval.Hourly,
       platformChannelSpecifics,
       );
   }

и я вызываю эту функцию для выполнения

 Future<void> smartnotificationcall(channelname,id)
 async{
   if(channelname=="clean"){ Duration(seconds:5); return _scheduleNotification(1,20,'clean',"clean","clean","clean.wav",'test','test');}
   if(channelname=="sport"){ Duration(seconds:20); return _scheduleNotification(2,30,"sport","sport","sport","sport.wav",'test','test');}
   if(channelname=="eat"){ Duration(seconds:40); return _scheduleNotification(3,30,"eat","eat","eat","eat.wav",'test','test');}
   if(channelname=="getout"){ Duration(seconds:50); return _scheduleNotification(4,30,"getout","getout","getout","getout.wav",'test','test');
 } 
}

1 Ответ

0 голосов
/ 16 апреля 2020

Какую платформу вы используете? Android использует AlarmManager для планирования повторяющихся уведомлений, и они являются неточными, и это задокументировано Android поведение.

...