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 · 1 comment
Open

Add initTimezones() #2493

Levi-Lesches opened this issue Dec 13, 2024 · 1 comment

Comments

@Levi-Lesches
Copy link
Contributor

Levi-Lesches commented Dec 13, 2024

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 mainly 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() {
  if (kIsWeb || Platform.isLinux) return;
  tz.initializeTimeZones();
  if (Platform.isWindows) return;
  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.

@MaikuB
Copy link
Owner

MaikuB commented Jan 29, 2025

To be more precise it's considered core only for those that need to schedule notifications. Putting that aside, I understand the intent but this is better placed in to reside in another (helper) package . This proposal forces this plugin to depend on flutter_timezone and in turn brings in an additional dependency upon apps that may not need. It can also bring about another potential point of failure that has been an issue before with the plugin this forked from. I think I had made a similar comment elsewhere, perhaps when one of your PRs that wanted to use msix (?)

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

2 participants