将整数转换为时间,然后在该时间安排通知。

huangapple go评论69阅读模式
英文:

Convert Integer to time and then schedule a notification on that time

问题

我首先需要将整数转换为时间(到目前为止我已经做到了),然后我想在那个时间安排一个通知。你看到那个复选框,当有人点击它时,闹钟会被设置。所以我不想设置多个闹钟。最重要的是,我不能使用Flutter的默认时间选择器(那个是有效的),但我不能使用它,因为我是用我的默认时间选择器设置闹钟。

现在我想获取那个值,将其转换为时间,并在那个时间设置通知。
提前感谢大家的帮助闹钟应用程序屏幕

我尝试了flutter_local_notifications包,但似乎无法弄清楚如何获取整数值并将其设置为安排通知。

英文:

First I have to convert the integer to time (which I've managed to do so far) and then I want to schedule a notification on that time. You see that checkbox, When someone taps then alarm is set. So I don't multiple alarms. And most importantly I can't flutter default time picker (That works) but I can't use since I'm setting the alarm with my default time picker.

Now I want to take that value and convert that to time and set a notification on that time.
Thanks everyone in advance Alarm App Screen

I've tried flutter_local_notifications package but I can't seem to figure out how can I take the integer value and set it to schedule notification.

答案1

得分: 1

如果我理解你的意思正确,你想要将整数转换为日期时间并用它来安排通知。

要将整数转换为日期时间,你可以指定当前日期并指定小时和分钟。

final now = DateTime.now();

DateTime(now.year, now.month, now.day, pm ? 12 + hour : hour, minute);

"pm" 将是一个可以由用户切换的布尔值,所以如果用户选择下午1点,小时将是13,因为小时必须采用24小时制格式。

在获取日期时间之后,可以使用 链接 中提到的方法来使用 flutterLocalNotifications 安排通知。

英文:

If I understand you correctly you mean you want to convert int to a DateTime and use it to schedule notifications.

to convert int to DateTime you can specify the current date and specify the hour and minute.

final now= DateTime.now();

DateTime(now.year,now.month,now.day,pm ? 12+ hour: hour, minute );

pm will be a bool that can be toogled by the user, so if the user picks 1pm the hr will be 13 since the hr has to be in 24hr format.

so after getting the dateTime use link to schedule notification with flutterLocalNotifications

huangapple
  • 本文由 发表于 2023年2月8日 14:26:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/75382058.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定