-
Notifications
You must be signed in to change notification settings - Fork 30.2k
[BUG] Getter 'isDst' not defined for 'TZDateTime' (package:timezone) on Dart 3.7.2 / Flutter 3.29.3 #169324
Description
Steps to reproduce
1.Create a new Flutter project: flutter create my_timezone_test_app
2.Navigate into the project directory: cd my_timezone_test_app
3.Add timezone package to pubspec.yaml:
dependencies:
flutter:
sdk: flutter
timezone: ^0.10.1 # Also tried with 0.9.2
# ... other dependencies
4.Run flutter pub get.
5.Replace the content of lib/main.dart with the following minimal reproducible code:
import 'package:flutter/material.dart';
import 'package:timezone/data/latest.dart' as tzdata;
import 'package:timezone/timezone.dart' as tz;
void main() async {
WidgetsFlutterBinding.ensureInitialized();
tzdata.initializeTimeZones();
final location = tz.getLocation('America/Los_Angeles');
final now = tz.TZDateTime.now(location);
print('Current time in ${location.name}: $now');
// Error occurs here:
if (now.isDst) {
print('DST is active in ${location.name}');
} else {
print('DST is NOT active in ${location.name}');
}
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
// TZDateTime and isDst usage in UI also shows the error if used
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Timezone Test')),
body: Center(child: Text('Is DST: ${tz.TZDateTime.now(tz.getLocation("America/Los_Angeles")).isDst}')),
),
);
}
}
6.Observe the error in the IDE (e.g., Android Studio) on the line if (now.isDst).
7.Try to run the app using flutter run or analyze using flutter analyze from the command line.
Expected results
The code should compile successfully, and now.isDst should return a boolean value indicating whether Daylight Saving Time is active for the given TZDateTime object.
Actual results
The Dart analyzer and compiler report the following error: The getter 'isDst' isn't defined for the type 'TZDateTime'.
This error occurs both in the IDE and when building/analyzing from the command line.
Code sample
Code sample
dependencies:
flutter:
sdk: flutter
timezone: ^0.10.1 # Also tried with 0.9.2
# ... other dependencies4.Run flutter pub get.
5.Replace the content of lib/main.dart with the following minimal reproducible code:
import 'package:flutter/material.dart';
import 'package:timezone/data/latest.dart' as tzdata;
import 'package:timezone/timezone.dart' as tz;
void main() async {
WidgetsFlutterBinding.ensureInitialized();
tzdata.initializeTimeZones();
final location = tz.getLocation('America/Los_Angeles');
final now = tz.TZDateTime.now(location);
print('Current time in ${location.name}: $now');
// Error occurs here:
if (now.isDst) {
print('DST is active in ${location.name}');
} else {
print('DST is NOT active in ${location.name}');
}
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
// TZDateTime and isDst usage in UI also shows the error if used
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Timezone Test')),
body: Center(child: Text('Is DST: ${tz.TZDateTime.now(tz.getLocation("America/Los_Angeles")).isDst}')),
),
);
}
}
Screenshots or Video
Screenshots / Video demonstration
[Upload media here]
Logs
Logs
[Paste your logs here]Flutter Doctor output
Doctor output
[√] Flutter (Channel stable, 3.29.3, on Microsoft Windows [Version 10.0.22631.5335], locale ja-JP) [336ms]
• Flutter version 3.29.3 on channel stable at C:\Users\a123l\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision ea121f8859 (6 weeks ago), 2025-04-11 19:10:07 +0000
• Engine revision cf56914b32
• Dart version 3.7.2
• DevTools version 2.42.3
[√] Windows Version (11 Home 64-bit, 23H2, 2009) [1,433ms]
[√] Android toolchain - develop for Android devices (Android SDK version 36.0.0) [3.0s]
• Android SDK at C:\Users\a123l\AppData\Local\Android\sdk
• Platform android-36, build-tools 36.0.0
• Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
This is the JDK bundled with the latest Android Studio installation on this machine.
To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
• Java version OpenJDK Runtime Environment (build 21.0.6+-13368085-b895.109)
• All Android licenses accepted.
[X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe) [17ms]
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[X] Visual Studio - develop Windows apps [15ms]
X Visual Studio not installed; this is necessary to develop Windows apps.
Download at https://visualstudio.microsoft.com/downloads/.
Please install the "Desktop development with C++" workload, including all of its default components
[√] Android Studio (version 2024.3.2) [13ms]
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 21.0.6+-13368085-b895.109)
[√] Connected device (2 available) [228ms]
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22631.5335]
• Edge (web) • edge • web-javascript • Microsoft Edge 136.0.3240.76
[√] Network resources [446ms]
• All expected network resources are available.
! Doctor found issues in 2 categories.