registerTask method

Future<void> registerTask(
  1. LocalNotificationModel notification
)

Implementation

Future<void> registerTask(LocalNotificationModel notification) async {
  if (notification.date == null) {
    throw Exception("date must provide d to schedule notification");
  }
  final DateTime scheduleDate = DateTime(
    notification.date!.year,
    notification.date!.month,
    notification.date!.day,
    notification.date!.hour,
    notification.date!.minute,
  );
  if (!scheduleDate.isAfter(DateTime.now())) {
    throw Exception("date must be in future");
  }
  await Workmanager().registerOneOffTask(
    "${notification.id}",
    notification.title.toString(),
    inputData: notification.toJson(),
    initialDelay: Duration(seconds: 4),
    constraints: Constraints(
      networkType: NetworkType.not_required,
      requiresBatteryNotLow: true,
      requiresCharging: false,
      requiresDeviceIdle: false,
      requiresStorageNotLow: false,
    ),
  );
}