转换为Map
Map<String, dynamic> toMap() { return { 'type': type.name, if (data != null) 'data': data, if (error != null) 'error': error, }; }