fromJson static method
Returns a new CombatSimulationDataSchema instance and imports its values from
value if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static CombatSimulationDataSchema? fromJson(dynamic value) {
if (value is Map) {
final json = value.cast<String, dynamic>();
// Ensure that the map contains the required keys.
// Note 1: the values aren't checked for validity beyond being non-null.
// Note 2: this code is stripped in release mode!
assert(() {
assert(json.containsKey(r'results'),
'Required key "CombatSimulationDataSchema[results]" is missing from JSON.');
assert(json[r'results'] != null,
'Required key "CombatSimulationDataSchema[results]" has a null value in JSON.');
assert(json.containsKey(r'wins'),
'Required key "CombatSimulationDataSchema[wins]" is missing from JSON.');
assert(json[r'wins'] != null,
'Required key "CombatSimulationDataSchema[wins]" has a null value in JSON.');
assert(json.containsKey(r'losses'),
'Required key "CombatSimulationDataSchema[losses]" is missing from JSON.');
assert(json[r'losses'] != null,
'Required key "CombatSimulationDataSchema[losses]" has a null value in JSON.');
assert(json.containsKey(r'winrate'),
'Required key "CombatSimulationDataSchema[winrate]" is missing from JSON.');
assert(json[r'winrate'] != null,
'Required key "CombatSimulationDataSchema[winrate]" has a null value in JSON.');
return true;
}());
return CombatSimulationDataSchema(
results: CombatResultSchema.listFromJson(json[r'results']),
wins: mapValueOfType<int>(json, r'wins')!,
losses: mapValueOfType<int>(json, r'losses')!,
winrate: num.parse('${json[r'winrate']}'),
);
}
return null;
}