Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initTimezones() #2493

Open
Levi-Lesches opened this issue Dec 13, 2024 · 0 comments
Open

Add initTimezones() #2493

Levi-Lesches opened this issue Dec 13, 2024 · 0 comments

Comments

@Levi-Lesches
Copy link
Contributor

Using TZDateTime correctly is a core part of this package. As such, the user needs to understand a bit of how package:timezone works. While writing the new usage guide, I realized that there is only really one correct way to do this, and based on the example, I think it looks like this:

import 'package:flutter_timezone/flutter_timezone.dart';
import 'package:timezone/data/latest_all.dart' as tz;
import 'package:timezone/timezone.dart' as tz;

void initTimezones() {
  // Not supported or needed on desktop and web platforms
  if (!Platform.isAndroid && !Platform.isIOS && !Platform.isMacOS) return;
  tz.initializeTimeZones();
  final timeZoneName = await FlutterTimezone.getLocalTimezone();
  tz.setLocalLocation(tz.getLocation(timeZoneName!));
}

From this point on, users can simply use tz.local to get their current tz.Location. So maybe instead of making everyone copy this snipper and adding both packages, maybe we can offer this as a top-level function and only make users include package:timezone, but not need to use getLocation and setLocalLocation themselves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant