1

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.

rafael__bg
  • 61
  • 4

1 Answers1

2

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.

rafael__bg
  • 61
  • 4