https://pub.dev/packages/awesome_notifications
Future<void> myNotifyScheduleInDays({
required int daysFromNow,
required String username,
required String refrigeName,
required String title,
required String msg,
bool repeatNotif = false,
}) async {
var nowDate = DateTime.now().add(Duration(days: daysFromNow, seconds: 5));
await AwesomeNotifications().createNotification(
schedule: NotificationCalendar(
preciseAlarm: true,
//weekday: nowDate.day,
day: nowDate.day,
minute: 5,
second: nowDate.second,
//allowWhileIdle: true,
),
// schedule: NotificationCalendar.fromDate(
// date: DateTime.now().add(const Duration(seconds: 10))),
content: NotificationContent(
id: -1,
channelKey: 'alerts',
wakeUpScreen: true,
category: NotificationCategory.Reminder,
title: '${Emojis.food_bowl_with_spoon} $refrigeName에 $title',
body: '$username 님, $msg',
largeIcon: 'asset://assets/images/lemon.png',
roundedLargeIcon: true,
autoDismissible: false,
notificationLayout: NotificationLayout.BigPicture,
//actionType : ActionType.DismissAction,
color: Colors.black,
backgroundColor: Colors.black,
// customSound: 'resource://raw/notif',
payload: {'actPag': 'myAct', 'actType': 'food', 'username': username},
),
actionButtons: [
NotificationActionButton(
key: 'NOW',
label: '확인',
),
// NotificationActionButton(
// key: 'LATER',
// label: 'btnAct2',
// ),
],
);
}
daysFromNow
변수를 통해 며칠 뒤에 알림을 보낼 것인지 결정할 수 있다.foreground
이거나 background
상태일 때 알림을 받을 수 있게 된다.