decodeJson method Null safety

void decodeJson(
  1. Map<String, dynamic> json,
  2. {required bool needsSave}
)

Convert from a data structure that comes from JSON. If there's an error in the middle, it might be partially read, but not in a way that causes bad behavior in the calculator.

Implementation

void decodeJson(Map<String, dynamic> json, {required bool needsSave}) {
  if (_jsonVersion != json['version']) {
    throw ArgumentError("Version ${json['version']} unrecognized");
  }
  _comments = json['comments'];
  settings.decodeJson(json['settings'] as Map<String, dynamic>);
  displayMode = DisplayMode.fromJson(json['displayMode']!);
  integerSignMode =
      IntegerSignMode.fromJson(json['integerSignMode'] as String);
  wordSize = json['wordSize'] as int;
  int i = 0;
  for (final v in json['stack'] as List<dynamic>) {
    _stack[i++] = Value.fromJson(v as String);
  }
  _lastX = Value.fromJson(json['lastX'] as String);
  i = 0;
  for (final v in json['flags'] as List<dynamic>) {
    _flags[i++] = v as bool;
  }
  memory.decodeJson(json['memory'] as Map<String, dynamic>);
  Object? debugLog = json['debugLog'];
  if (debugLog == null) {
    _debugLog = null;
  } else {
    _debugLog = DebugLog.fromJson(debugLog as Map<String, dynamic>, this);
  }
  display.window = 0;
  _needsSave = needsSave;
}