pinkfish / flutter_native_timezone

Apache License 2.0
85 stars 179 forks source link

Flutter IOS getting this issue in latest version in tz.local #30

Closed Praveen-Ramalingam closed 3 years ago

Praveen-Ramalingam commented 3 years ago

Unhandled Exception: LateInitializationError: Field '_local@1885310200' has not been initialized.

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.2.2, on macOS 11.4 20F71 darwin-arm, locale
    en-IN)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor
      --android-licenses
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.57.0)
[✓] Connected device (2 available)

! Doctor found issues in 1 category.

Plugin version

flutter_native_timezone: ^2.0.0

Getting error while calling

import 'package:timezone/timezone.dart' as tz;
final tz.TZDateTime now = tz.TZDateTime.now(tz.local);

Please help i am getting this issue

Praveen-Ramalingam commented 3 years ago

Fixed after initializing the timeZones

tz.initializeTimeZones();  f
inal String? timeZoneName = await FlutterNativeTimezone.getLocalTimezone();  tz.setLocalLocation(tz.getLocation(timeZoneName!));
}