Skip to content

Field '_local' has not been initialized. #226

@sewakghali

Description

@sewakghali

Logs:

Error : LateInitializationError: Field '_local@890310200' has not been initialized. #0      _local (package:timezone/src/env.dart)
#1      local (package:timezone/src/env.dart:26:23)
#2      TZDateTime.isLocal (package:timezone/src/date_time.dart:121:43)
#3      TZDateTime.toLocal (package:timezone/src/date_time.dart:266:27)

The problem comes out to be in src/env.dart:

...
final _UTC = Location('UTC', [minTime], [0], [TimeZone.UTC]);
...
late Location _local;
...
/// Local Location
///
/// By default it is instantiated with UTC [Location]
Location get local => _local;
Location getLocation(String locationName) {
  return _database.get(locationName);
}
void setLocalLocation(Location location) {
  _local = location;
}

void initializeDatabase(List<int> rawData) {
  _database.clear();

  for (final l in tzdbDeserialize(rawData)) {
    _database.add(l);
  }

  _local = _UTC;
}

Why not directly assign _UTC to _local, and remove the late modifier. It is set as fallback already, or am I missing something?

Location _local = _UTC;

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs infoThe issue needs more information to act on

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions