Open reesz opened 2 years ago
have you discovered the ideal solution for this?
@lucasribolli sadly not, we've just used the workaround of re-initiating the timezone since then:
tz.initializeTimeZones();
final String timeZoneName = await FlutterNativeTimezone.getLocalTimezone();
tz.setLocalLocation(tz.getLocation(timeZoneName));
before the tz.TZDateTime.local
call.
Version in use:
timezone: ^0.7.0-nullsafety.0
Flutter doctor:
I'm using the following way with the flutter_native_timezone package to determine the users timezone:
One weird thing that seems to happen with my setup since the Flutter 2 upgrade: I'm doing the full timezone init + location setting right at the top of main.dart (which works fine):
and in a helper service in another file
notification_helper.dart
im using static methods to schedule local notifications using the flutter_local_notifications package. But when I access the tz methods in there:and print the tz's local it's reset to UTC which then gives a UTC timezone DateTime from
TZDateTime.local
instead of the correct one (in my case Europe/Berlin). Oddly this seems to have worked before the Flutter 2 update, since we were using this setup for ~1 year without problems. A dirty fix would be to just re-init and re-set the timezone everytime in thetoLocalDateTime
method.Shouldn't there a more elegant way of correctly setting the location over multiple places or am I missing something here?