MBSection.fromDictionary constructor
Initializes a section with the dictionary returned by the api.
- Parameters:
dictionary
: Thedictionary
returned by the APIs response
Implementation
factory MBSection.fromDictionary(Map<String, dynamic> dictionary) {
int id = dictionary['id'] as int;
int order = dictionary['order'] as int;
Map<String, MBElement> elements = {};
int timestamp = dictionary['available_at'] as int;
DateTime availableAt =
DateTime.fromMillisecondsSinceEpoch(timestamp * 1000);
bool inEvidence = false;
if (dictionary['in_evidence'] is bool) {
inEvidence = dictionary['in_evidence'] as bool;
}
if (dictionary['elements'] is Map<String, dynamic>) {
Map<String, dynamic> elementsFromApi =
dictionary['elements'] as Map<String, dynamic>;
for (String key in elementsFromApi.keys) {
elements[key] = MBElementsUtilities.elementFromDictionary(
elementsFromApi[key] as Map<String, dynamic>,
);
}
}
return MBSection(
id: id,
order: order,
elements: elements,
availableAt: availableAt,
inEvidence: inEvidence,
);
}