make event model const

This commit is contained in:
Salvatore Giordano
2021-04-20 09:50:09 +02:00
parent 79769acef0
commit 4a094629d1
2 changed files with 34 additions and 43 deletions
+14 -13
View File
@@ -10,7 +10,7 @@ part 'event.g.dart';
@JsonSerializable()
class Event {
/// Constructor used for json serialization
Event({
const Event({
this.type,
this.cid,
this.connectionId,
@@ -27,16 +27,18 @@ class Event {
this.channelId,
this.channelType,
this.parentId,
this.extraData,
}) : isLocal = true;
this.extraData = const {},
this.isLocal = true,
});
/// Create a new instance from a json
factory Event.fromJson(Map<String, dynamic> json) =>
_$EventFromJson(Serialization.moveToExtraDataFromRoot(
json,
topLevelFields,
))
..isLocal = false;
factory Event.fromJson(Map<String, dynamic> json) => _$EventFromJson({
...Serialization.moveToExtraDataFromRoot(
json,
topLevelFields,
),
'is_local': false,
});
/// The type of the event
/// [EventType] contains some predefined constant types
@@ -89,11 +91,11 @@ class Event {
/// True if the event is generated by this client
@JsonKey(ignore: true)
bool isLocal;
final bool isLocal;
/// Map of custom channel extraData
@JsonKey(includeIfNull: false)
final Map<String, dynamic>? extraData;
@JsonKey(defaultValue: {})
final Map<String, dynamic> extraData;
/// Known top level fields.
/// Useful for [Serialization] methods.
@@ -114,7 +116,6 @@ class Event {
'channel_id',
'channel_type',
'parent_id',
'is_local',
];
/// Serialize to json