I'm using flutter_local_notifications
plug-in to send notifications to my users. But I need to schedule the notifications. So I use zonedSchedule()
to do that. The problem is that zonedSchedule()
requires TZDateTime, so I need to convert DateTime to TZDateTime. I saw this question, but it didn't work for me. I just need to get the Location
of the user and pass to TZDateTime.from(dateTime,location)
. How can I get this location?
Thanks in advance.
I've just asked this question but I have the answer already. For those having trouble with the Location
, you can just use tz.getLocation(await FlutterNativeTimezone.getLocalTimezone())
to get the location
parameter for TZDateTime.from(dateTime,location)
.
PS.: Remember to import: import 'package:timezone/data/latest.dart' as tz;
and import 'package:timezone/timezone.dart' as tz;
.
Also, you have to inicialize tz
:
tz.initializeTimeZones();
tz.setLocalLocation(tz.getLocation(await FlutterNativeTimezone.getLocalTimezone()));
That's it, I hope it's useful.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.