time_machine icon indicating copy to clipboard operation
time_machine copied to clipboard

NoSuchMethodError: The getter 'id' was called on null

Open SteveAlexander opened this issue 6 years ago • 1 comments

This was reported via Sentry.io, with an app that is using flutter_native_timezone.

The problem is in vm.dart, line 91

    var local = timeZoneOverride != null ? await tzdb.getZoneOrNull(timeZoneOverride) : await _figureOutTimeZone(tzdb);
    // todo: cache local more directly? (this is indirect caching)
    TzdbIndex.localId = local.id;

Getting local.id fails because local is null.

I think the culprit is tzdb.getZoneOrNull that might return null.

I guess if it returns null, Perhaps timemachine should log a warning message, and then resort to _figureOutTimeZone

SteveAlexander avatar Feb 15 '19 14:02 SteveAlexander

I had the same problem when executing the following code on an android emulator:

await TimeMachine.initialize({
  'rootBundle': rootBundle,
  'timeZone': await FlutterNativeTimezone.getLocalTimezone(),
});

The exception occurred because FlutterNativeTimezone.getLocalTimezone() returned GMT, which could not be resolved by TimeMachine. To fix this, I now manually change GMT to UTC:

var timeZone = await FlutterNativeTimezone.getLocalTimezone();
if (timeZone == 'GMT') {
  timeZone = 'UTC';
}
await TimeMachine.initialize({
  'rootBundle': rootBundle,
  'timeZone': timeZone,
});

JonasWanke avatar Mar 11 '20 15:03 JonasWanke