-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathrealtime_response.dart
More file actions
55 lines (45 loc) · 1.21 KB
/
realtime_response.dart
File metadata and controls
55 lines (45 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import 'dart:convert';
import 'package:flutter/foundation.dart';
class RealtimeResponse {
final String type; // error, event, connected, response
final Map<String, dynamic> data;
RealtimeResponse({
required this.type,
required this.data,
});
RealtimeResponse copyWith({
String? type,
Map<String, dynamic>? data,
}) {
return RealtimeResponse(
type: type ?? this.type,
data: data ?? this.data,
);
}
Map<String, dynamic> toMap() {
return {
'type': type,
'data': data,
};
}
factory RealtimeResponse.fromMap(Map<String, dynamic> map) {
return RealtimeResponse(
type: map['type'],
data: Map<String, dynamic>.from(map['data'] ?? {}),
);
}
String toJson() => json.encode(toMap());
factory RealtimeResponse.fromJson(String source) =>
RealtimeResponse.fromMap(json.decode(source));
@override
String toString() => 'RealtimeResponse(type: $type, data: $data)';
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
return other is RealtimeResponse &&
other.type == type &&
mapEquals(other.data, data);
}
@override
int get hashCode => type.hashCode ^ data.hashCode;
}