toJSON method
Transforms this instance into a JSON object.
Implementation
Map<String,dynamic> toJSON() {
final Map<String,dynamic> json = {
'owner': owner?.uuid,
'currentState': null,
'previousState': null,
'globalState': null,
'states': []
};
final Map<String,dynamic> statesMap = {};
// states
for ( final s in states.keys ) {
final id = s;
final state = states[s];
json['states'].add( {
'type': runtimeType.toString(),
'id': id,
'state': state?.toJSON()
} );
statesMap[id] = state;
}
json['currentState'] = statesMap['currentState'];
json['previousState'] = statesMap['previousState'];
json['globalState'] = statesMap['globalState'];
return json;
}