time_machine
time_machine copied to clipboard
NoSuchMethodError: The getter 'id' was called on null
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
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,
});