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.

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This is also written in the documentation for flutter_local_notifications

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.