Skip to content

Commit

Permalink
[FIX] get list of timezones on Web (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
HosamHasanRamadan authored Aug 21, 2024
1 parent 9a68eae commit 67aab8e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/flutter_timezone_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class FlutterTimezonePlugin {
case 'getLocalTimezone':
return _getLocalTimeZone();
case 'getAvailableTimezones':
return [_getLocalTimeZone()];
return _getAvailableTimezones();
default:
throw PlatformException(
code: 'Unimplemented',
Expand All @@ -40,8 +40,18 @@ class FlutterTimezonePlugin {
String _getLocalTimeZone() {
return jsDateTimeFormat().resolvedOptions().timeZone;
}

List<String> _getAvailableTimezones() {
final function = supportedValuesOf as _DartFunctionSupportedValuesOf?;
return function?.call('timeZone') ?? [_getLocalTimeZone()];
}
}

typedef _DartFunctionSupportedValuesOf = List<String> Function(String value);

@JS('Intl.supportedValuesOf')
external JSFunction? supportedValuesOf;

@JS('Intl.DateTimeFormat')
external _JSDateTimeFormat jsDateTimeFormat();

Expand Down

0 comments on commit 67aab8e

Please sign in to comment.