refactor: initializer lists in fromJson constructors

This commit is contained in:
Lukas Lihotzki 2021-05-05 12:05:26 +02:00
parent 23db25d4af
commit 9de57fad9b
48 changed files with 372 additions and 401 deletions

View File

@ -27,10 +27,9 @@ class AuthenticationData {
AuthenticationData({this.type, this.session}); AuthenticationData({this.type, this.session});
AuthenticationData.fromJson(Map<String, dynamic> json) { AuthenticationData.fromJson(Map<String, dynamic> json)
type = json['type']; : type = json['type'],
session = json['session']; session = json['session'];
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -26,9 +26,8 @@ class AuthenticationIdentifier {
AuthenticationIdentifier({this.type}); AuthenticationIdentifier({this.type});
AuthenticationIdentifier.fromJson(Map<String, dynamic> json) { AuthenticationIdentifier.fromJson(Map<String, dynamic> json)
type = json['type']; : type = json['type'];
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -45,10 +45,10 @@ class AuthenticationPassword extends AuthenticationData {
); );
AuthenticationPassword.fromJson(Map<String, dynamic> json) AuthenticationPassword.fromJson(Map<String, dynamic> json)
: super.fromJson(json) { : user = json['user'],
user = json['user']; password = json['password'],
password = json['password']; identifier = AuthenticationIdentifier.fromJson(json['identifier']),
identifier = AuthenticationIdentifier.fromJson(json['identifier']); super.fromJson(json) {
switch (identifier.type) { switch (identifier.type) {
case AuthenticationIdentifierTypes.userId: case AuthenticationIdentifierTypes.userId:
identifier = AuthenticationUserIdentifier.fromJson(json['identifier']); identifier = AuthenticationUserIdentifier.fromJson(json['identifier']);

View File

@ -32,10 +32,9 @@ class AuthenticationPhoneIdentifier extends AuthenticationIdentifier {
: super(type: AuthenticationIdentifierTypes.phone); : super(type: AuthenticationIdentifierTypes.phone);
AuthenticationPhoneIdentifier.fromJson(Map<String, dynamic> json) AuthenticationPhoneIdentifier.fromJson(Map<String, dynamic> json)
: super.fromJson(json) { : country = json['country'],
country = json['country']; phone = json['phone'],
phone = json['phone']; super.fromJson(json);
}
@override @override
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {

View File

@ -34,9 +34,8 @@ class AuthenticationRecaptcha extends AuthenticationData {
); );
AuthenticationRecaptcha.fromJson(Map<String, dynamic> json) AuthenticationRecaptcha.fromJson(Map<String, dynamic> json)
: super.fromJson(json) { : response = json['response'],
response = json['response']; super.fromJson(json);
}
@override @override
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {

View File

@ -32,10 +32,9 @@ class AuthenticationThirdPartyIdentifier extends AuthenticationIdentifier {
: super(type: AuthenticationIdentifierTypes.thirdParty); : super(type: AuthenticationIdentifierTypes.thirdParty);
AuthenticationThirdPartyIdentifier.fromJson(Map<String, dynamic> json) AuthenticationThirdPartyIdentifier.fromJson(Map<String, dynamic> json)
: super.fromJson(json) { : medium = json['medium'],
medium = json['medium']; address = json['address'],
address = json['address']; super.fromJson(json);
}
@override @override
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {

View File

@ -72,12 +72,11 @@ class ThreepidCreds {
ThreepidCreds( ThreepidCreds(
{this.sid, this.clientSecret, this.idServer, this.idAccessToken}); {this.sid, this.clientSecret, this.idServer, this.idAccessToken});
ThreepidCreds.fromJson(Map<String, dynamic> json) { ThreepidCreds.fromJson(Map<String, dynamic> json)
sid = json['sid']; : sid = json['sid'],
clientSecret = json['client_secret']; clientSecret = json['client_secret'],
idServer = json['id_server']; idServer = json['id_server'],
idAccessToken = json['id_access_token']; idAccessToken = json['id_access_token'];
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -35,10 +35,9 @@ class AuthenticationToken extends AuthenticationData {
); );
AuthenticationToken.fromJson(Map<String, dynamic> json) AuthenticationToken.fromJson(Map<String, dynamic> json)
: super.fromJson(json) { : token = json['token'],
token = json['token']; txnId = json['txn_id'],
txnId = json['txn_id']; super.fromJson(json);
}
@override @override
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {

View File

@ -31,9 +31,8 @@ class AuthenticationUserIdentifier extends AuthenticationIdentifier {
: super(type: AuthenticationIdentifierTypes.userId); : super(type: AuthenticationIdentifierTypes.userId);
AuthenticationUserIdentifier.fromJson(Map<String, dynamic> json) AuthenticationUserIdentifier.fromJson(Map<String, dynamic> json)
: super.fromJson(json) { : user = json['user'],
user = json['user']; super.fromJson(json);
}
@override @override
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {

View File

@ -32,10 +32,10 @@ class BasicEvent {
this.content, this.content,
}); });
BasicEvent.fromJson(Map<String, dynamic> json) { BasicEvent.fromJson(Map<String, dynamic> json)
type = json['type']; : type = json['type'],
content = (json['content'] as Map<String, dynamic>).copy(); content = (json['content'] as Map<String, dynamic>).copy();
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};
data['type'] = type; data['type'] = type;

View File

@ -29,9 +29,8 @@ class BasicEventWithSender extends BasicEvent {
BasicEventWithSender(); BasicEventWithSender();
BasicEventWithSender.fromJson(Map<String, dynamic> json) BasicEventWithSender.fromJson(Map<String, dynamic> json)
: super.fromJson(json) { : senderId = json['sender'],
senderId = json['sender']; super.fromJson(json);
}
@override @override
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {

View File

@ -35,9 +35,9 @@ class BasicRoomEvent extends BasicEvent {
type: type, type: type,
); );
BasicRoomEvent.fromJson(Map<String, dynamic> json) : super.fromJson(json) { BasicRoomEvent.fromJson(Map<String, dynamic> json)
roomId = json['room_id']; : roomId = json['room_id'],
} super.fromJson(json);
@override @override
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {

View File

@ -27,12 +27,12 @@ class Device {
String lastSeenIp; String lastSeenIp;
DateTime lastSeenTs; DateTime lastSeenTs;
Device.fromJson(Map<String, dynamic> json) { Device.fromJson(Map<String, dynamic> json)
deviceId = json['device_id']; : deviceId = json['device_id'],
displayName = json['display_name']; displayName = json['display_name'],
lastSeenIp = json['last_seen_ip']; lastSeenIp = json['last_seen_ip'],
lastSeenTs = DateTime.fromMillisecondsSinceEpoch(json['last_seen_ts'] ?? 0); lastSeenTs =
} DateTime.fromMillisecondsSinceEpoch(json['last_seen_ts'] ?? 0);
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -31,25 +31,26 @@ class EventContext {
String start; String start;
List<MatrixEvent> state; List<MatrixEvent> state;
EventContext.fromJson(Map<String, dynamic> json) { EventContext.fromJson(Map<String, dynamic> json)
end = json['end']; : end = json['end'],
if (json['events_after'] != null) { eventsAfter = (json['events_after'] != null)
eventsAfter = (json['events_after'] as List) ? (json['events_after'] as List)
.map((v) => MatrixEvent.fromJson(v)) .map((v) => MatrixEvent.fromJson(v))
.toList(); .toList()
} : null,
event = json['event'] != null ? MatrixEvent.fromJson(json['event']) : null; event =
if (json['events_before'] != null) { json['event'] != null ? MatrixEvent.fromJson(json['event']) : null,
eventsBefore = (json['events_before'] as List) eventsBefore = (json['events_before'] != null)
.map((v) => MatrixEvent.fromJson(v)) ? (json['events_before'] as List)
.toList(); .map((v) => MatrixEvent.fromJson(v))
} .toList()
start = json['start']; : null,
if (json['state'] != null) { start = json['start'],
state = state = (json['state'] != null)
(json['state'] as List).map((v) => MatrixEvent.fromJson(v)).toList(); ? (json['state'] as List)
} .map((v) => MatrixEvent.fromJson(v))
} .toList()
: null;
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -28,13 +28,14 @@ class EventsSyncUpdate {
String end; String end;
List<MatrixEvent> chunk; List<MatrixEvent> chunk;
EventsSyncUpdate.fromJson(Map<String, dynamic> json) { EventsSyncUpdate.fromJson(Map<String, dynamic> json)
start = json['start']; : start = json['start'],
end = json['end']; end = json['end'],
chunk = json['chunk'] != null chunk = json['chunk'] != null
? (json['chunk'] as List).map((i) => MatrixEvent.fromJson(i)).toList() ? (json['chunk'] as List)
: null; .map((i) => MatrixEvent.fromJson(i))
} .toList()
: null;
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -38,22 +38,21 @@ class Filter {
this.eventFields, this.eventFields,
}); });
Filter.fromJson(Map<String, dynamic> json) { Filter.fromJson(Map<String, dynamic> json)
room = json['room'] != null ? RoomFilter.fromJson(json['room']) : null; : room = json['room'] != null ? RoomFilter.fromJson(json['room']) : null,
presence = json['presence'] != null presence = json['presence'] != null
? EventFilter.fromJson(json['presence']) ? EventFilter.fromJson(json['presence'])
: null; : null,
accountData = json['account_data'] != null accountData = json['account_data'] != null
? EventFilter.fromJson(json['account_data']) ? EventFilter.fromJson(json['account_data'])
: null; : null,
eventFormat = json['event_format'] != null eventFormat = json['event_format'] != null
? EventFormat.values.firstWhere( ? EventFormat.values.firstWhere(
(e) => e.toString().split('.').last == json['event_format']) (e) => e.toString().split('.').last == json['event_format'])
: null; : null,
eventFields = json['event_fields'] != null eventFields = json['event_fields'] != null
? json['event_fields'].cast<String>() ? json['event_fields'].cast<String>()
: null; : null;
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -31,48 +31,45 @@ class KeysQueryResponse {
Map<String, MatrixCrossSigningKey> selfSigningKeys; Map<String, MatrixCrossSigningKey> selfSigningKeys;
Map<String, MatrixCrossSigningKey> userSigningKeys; Map<String, MatrixCrossSigningKey> userSigningKeys;
KeysQueryResponse.fromJson(Map<String, dynamic> json) { KeysQueryResponse.fromJson(Map<String, dynamic> json)
failures = (json['failures'] as Map<String, dynamic>)?.copy(); : failures = (json['failures'] as Map<String, dynamic>)?.copy(),
deviceKeys = json['device_keys'] != null deviceKeys = json['device_keys'] != null
? (json['device_keys'] as Map).map( ? (json['device_keys'] as Map).map(
(k, v) => MapEntry(
k,
(v as Map).map(
(k, v) => MapEntry( (k, v) => MapEntry(
k, k,
MatrixDeviceKeys.fromJson(v), (v as Map).map(
(k, v) => MapEntry(
k,
MatrixDeviceKeys.fromJson(v),
),
),
), ),
), )
), : null,
) masterKeys = json['master_keys'] != null
: null; ? (json['master_keys'] as Map).map(
masterKeys = json['master_keys'] != null (k, v) => MapEntry(
? (json['master_keys'] as Map).map( k,
(k, v) => MapEntry( MatrixCrossSigningKey.fromJson(v),
k, ),
MatrixCrossSigningKey.fromJson(v), )
), : null,
) selfSigningKeys = json['self_signing_keys'] != null
: null; ? (json['self_signing_keys'] as Map).map(
(k, v) => MapEntry(
selfSigningKeys = json['self_signing_keys'] != null k,
? (json['self_signing_keys'] as Map).map( MatrixCrossSigningKey.fromJson(v),
(k, v) => MapEntry( ),
k, )
MatrixCrossSigningKey.fromJson(v), : null,
), userSigningKeys = json['user_signing_keys'] != null
) ? (json['user_signing_keys'] as Map).map(
: null; (k, v) => MapEntry(
k,
userSigningKeys = json['user_signing_keys'] != null MatrixCrossSigningKey.fromJson(v),
? (json['user_signing_keys'] as Map).map( ),
(k, v) => MapEntry( )
k, : null;
MatrixCrossSigningKey.fromJson(v),
),
)
: null;
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -29,14 +29,13 @@ class LoginResponse {
String deviceId; String deviceId;
WellKnownInformation wellKnownInformation; WellKnownInformation wellKnownInformation;
LoginResponse.fromJson(Map<String, dynamic> json) { LoginResponse.fromJson(Map<String, dynamic> json)
userId = json['user_id']; : userId = json['user_id'],
accessToken = json['access_token']; accessToken = json['access_token'],
deviceId = json['device_id']; deviceId = json['device_id'],
if (json['well_known'] is Map) { wellKnownInformation = (json['well_known'] is Map)
wellKnownInformation = WellKnownInformation.fromJson(json['well_known']); ? WellKnownInformation.fromJson(json['well_known'])
} : null;
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -34,15 +34,15 @@ class MatrixEvent extends StrippedStateEvent {
MatrixEvent(); MatrixEvent();
MatrixEvent.fromJson(Map<String, dynamic> json) : super.fromJson(json) { MatrixEvent.fromJson(Map<String, dynamic> json)
eventId = json['event_id']; : eventId = json['event_id'],
roomId = json['room_id']; roomId = json['room_id'],
originServerTs = originServerTs =
DateTime.fromMillisecondsSinceEpoch(json['origin_server_ts']); DateTime.fromMillisecondsSinceEpoch(json['origin_server_ts']),
unsigned = (json['unsigned'] as Map<String, dynamic>)?.copy(); unsigned = (json['unsigned'] as Map<String, dynamic>)?.copy(),
prevContent = (json['prev_content'] as Map<String, dynamic>)?.copy(); prevContent = (json['prev_content'] as Map<String, dynamic>)?.copy(),
redacts = json['redacts']; redacts = json['redacts'],
} super.fromJson(json);
@override @override
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {

View File

@ -36,17 +36,16 @@ class MatrixSignableKey {
// This object is used for signing so we need the raw json too // This object is used for signing so we need the raw json too
Map<String, dynamic> _json; Map<String, dynamic> _json;
MatrixSignableKey.fromJson(Map<String, dynamic> json) { MatrixSignableKey.fromJson(Map<String, dynamic> json)
_json = json; : _json = json,
userId = json['user_id']; userId = json['user_id'],
keys = Map<String, String>.from(json['keys']); keys = Map<String, String>.from(json['keys']),
// we need to manually copy to ensure that our map is Map<String, Map<String, String>> // we need to manually copy to ensure that our map is Map<String, Map<String, String>>
signatures = json['signatures'] is Map signatures = json['signatures'] is Map
? Map<String, Map<String, String>>.from((json['signatures'] as Map) ? Map<String, Map<String, String>>.from((json['signatures'] as Map)
.map((k, v) => MapEntry(k, Map<String, String>.from(v)))) .map((k, v) => MapEntry(k, Map<String, String>.from(v))))
: null; : null,
unsigned = (json['unsigned'] as Map<String, dynamic>)?.copy(); unsigned = (json['unsigned'] as Map<String, dynamic>)?.copy();
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = _json ?? <String, dynamic>{}; final data = _json ?? <String, dynamic>{};

View File

@ -27,12 +27,11 @@ class NotificationsQueryResponse {
String nextToken; String nextToken;
List<Notification> notifications; List<Notification> notifications;
NotificationsQueryResponse.fromJson(Map<String, dynamic> json) { NotificationsQueryResponse.fromJson(Map<String, dynamic> json)
nextToken = json['next_token']; : nextToken = json['next_token'],
notifications = (json['notifications'] as List) notifications = (json['notifications'] as List)
.map((v) => Notification.fromJson(v)) .map((v) => Notification.fromJson(v))
.toList(); .toList();
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -27,12 +27,11 @@ class OneTimeKeysClaimResponse {
Map<String, dynamic> failures; Map<String, dynamic> failures;
Map<String, Map<String, dynamic>> oneTimeKeys; Map<String, Map<String, dynamic>> oneTimeKeys;
OneTimeKeysClaimResponse.fromJson(Map<String, dynamic> json) { OneTimeKeysClaimResponse.fromJson(Map<String, dynamic> json)
failures = (json['failures'] as Map<String, dynamic>)?.copy() ?? {}; : failures = (json['failures'] as Map<String, dynamic>)?.copy() ?? {},
// We still need a Map<...>.from(...) to ensure all second-level entries are also maps // We still need a Map<...>.from(...) to ensure all second-level entries are also maps
oneTimeKeys = Map<String, Map<String, dynamic>>.from( oneTimeKeys = Map<String, Map<String, dynamic>>.from(
(json['one_time_keys'] as Map<String, dynamic>).copy()); (json['one_time_keys'] as Map<String, dynamic>).copy());
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -30,15 +30,14 @@ class OpenGraphData {
int ogImageWidth; int ogImageWidth;
int matrixImageSize; int matrixImageSize;
OpenGraphData.fromJson(Map<String, dynamic> json) { OpenGraphData.fromJson(Map<String, dynamic> json)
ogTitle = json['og:title']; : ogTitle = json['og:title'],
ogDescription = json['og:description']; ogDescription = json['og:description'],
ogImage = json['og:image']; ogImage = json['og:image'],
ogImageType = json['og:image:type']; ogImageType = json['og:image:type'],
ogImageHeight = json['og:image:height']; ogImageHeight = json['og:image:height'],
ogImageWidth = json['og:image:width']; ogImageWidth = json['og:image:width'],
matrixImageSize = json['matrix:image:size']; matrixImageSize = json['matrix:image:size'];
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -27,12 +27,11 @@ class OpenIdCredentials {
String matrixServerName; String matrixServerName;
double expiresIn; double expiresIn;
OpenIdCredentials.fromJson(Map<String, dynamic> json) { OpenIdCredentials.fromJson(Map<String, dynamic> json)
accessToken = json['access_token']; : accessToken = json['access_token'],
tokenType = json['token_type']; tokenType = json['token_type'],
matrixServerName = json['matrix_server_name']; matrixServerName = json['matrix_server_name'],
expiresIn = json['expires_in']; expiresIn = json['expires_in'];
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -27,7 +27,7 @@ import 'presence_content.dart';
class Presence extends BasicEventWithSender { class Presence extends BasicEventWithSender {
PresenceContent presence; PresenceContent presence;
Presence.fromJson(Map<String, dynamic> json) : super.fromJson(json) { Presence.fromJson(Map<String, dynamic> json)
presence = PresenceContent.fromJson(content); : presence = PresenceContent.fromJson(json['content']),
} super.fromJson(json);
} }

View File

@ -29,13 +29,12 @@ class PresenceContent {
String statusMsg; String statusMsg;
bool currentlyActive; bool currentlyActive;
PresenceContent.fromJson(Map<String, dynamic> json) { PresenceContent.fromJson(Map<String, dynamic> json)
presence = PresenceType.values : presence = PresenceType.values.firstWhere(
.firstWhere((p) => p.toString().split('.').last == json['presence']); (p) => p.toString().split('.').last == json['presence']),
lastActiveAgo = json['last_active_ago']; lastActiveAgo = json['last_active_ago'],
statusMsg = json['status_msg']; statusMsg = json['status_msg'],
currentlyActive = json['currently_active']; currentlyActive = json['currently_active'];
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -27,12 +27,12 @@ class PublicRoomsResponse {
String prevBatch; String prevBatch;
int totalRoomCountEstimate; int totalRoomCountEstimate;
PublicRoomsResponse.fromJson(Map<String, dynamic> json) { PublicRoomsResponse.fromJson(Map<String, dynamic> json)
chunk = (json['chunk'] as List).map((v) => PublicRoom.fromJson(v)).toList(); : chunk =
nextBatch = json['next_batch']; (json['chunk'] as List).map((v) => PublicRoom.fromJson(v)).toList(),
prevBatch = json['prev_batch']; nextBatch = json['next_batch'],
totalRoomCountEstimate = json['total_room_count_estimate']; prevBatch = json['prev_batch'],
} totalRoomCountEstimate = json['total_room_count_estimate'];
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};
@ -61,17 +61,16 @@ class PublicRoom {
bool worldReadable; bool worldReadable;
String canonicalAlias; String canonicalAlias;
PublicRoom.fromJson(Map<String, dynamic> json) { PublicRoom.fromJson(Map<String, dynamic> json)
aliases = json['aliases']?.cast<String>(); : aliases = json['aliases']?.cast<String>(),
avatarUrl = json['avatar_url']; avatarUrl = json['avatar_url'],
guestCanJoin = json['guest_can_join']; guestCanJoin = json['guest_can_join'],
canonicalAlias = json['canonical_alias']; canonicalAlias = json['canonical_alias'],
name = json['name']; name = json['name'],
numJoinedMembers = json['num_joined_members']; numJoinedMembers = json['num_joined_members'],
roomId = json['room_id']; roomId = json['room_id'],
topic = json['topic']; topic = json['topic'],
worldReadable = json['world_readable']; worldReadable = json['world_readable'];
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -42,16 +42,15 @@ class Pusher {
this.kind, this.kind,
}); });
Pusher.fromJson(Map<String, dynamic> json) { Pusher.fromJson(Map<String, dynamic> json)
pushkey = json['pushkey']; : pushkey = json['pushkey'],
kind = json['kind']; kind = json['kind'],
appId = json['app_id']; appId = json['app_id'],
appDisplayName = json['app_display_name']; appDisplayName = json['app_display_name'],
deviceDisplayName = json['device_display_name']; deviceDisplayName = json['device_display_name'],
profileTag = json['profile_tag']; profileTag = json['profile_tag'],
lang = json['lang']; lang = json['lang'],
data = PusherData.fromJson(json['data']); data = PusherData.fromJson(json['data']);
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};
@ -78,12 +77,9 @@ class PusherData {
this.format, this.format,
}); });
PusherData.fromJson(Map<String, dynamic> json) { PusherData.fromJson(Map<String, dynamic> json)
if (json.containsKey('url')) { : format = json['format'],
url = Uri.parse(json['url']); url = json.containsKey('url') ? Uri.parse(json['url']) : null;
}
format = json['format'];
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -25,10 +25,9 @@ class RequestTokenResponse {
String sid; String sid;
String submitUrl; String submitUrl;
RequestTokenResponse.fromJson(Map<String, dynamic> json) { RequestTokenResponse.fromJson(Map<String, dynamic> json)
sid = json['sid']; : sid = json['sid'],
submitUrl = json['submit_url']; submitUrl = json['submit_url'];
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -25,10 +25,9 @@ class RoomAliasInformation {
String roomId; String roomId;
List<String> servers; List<String> servers;
RoomAliasInformation.fromJson(Map<String, dynamic> json) { RoomAliasInformation.fromJson(Map<String, dynamic> json)
roomId = json['room_id']; : roomId = json['room_id'],
servers = json['servers'].cast<String>(); servers = json['servers'].cast<String>();
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -52,15 +52,14 @@ class RoomKeysVersionResponse {
String etag; String etag;
String version; String version;
RoomKeysVersionResponse.fromJson(Map<String, dynamic> json) { RoomKeysVersionResponse.fromJson(Map<String, dynamic> json)
algorithm = : algorithm = RoomKeysAlgorithmTypeExtension.fromAlgorithmString(
RoomKeysAlgorithmTypeExtension.fromAlgorithmString(json['algorithm']); json['algorithm']),
authData = json['auth_data']; authData = json['auth_data'],
count = json['count']; count = json['count'],
etag = etag = json['etag']
json['etag'].toString(); // synapse replies an int but docs say string? .toString(), // synapse replies an int but docs say string?
version = json['version']; version = json['version'];
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -33,12 +33,11 @@ class RoomKeysSingleKey {
this.isVerified, this.isVerified,
this.sessionData}); this.sessionData});
RoomKeysSingleKey.fromJson(Map<String, dynamic> json) { RoomKeysSingleKey.fromJson(Map<String, dynamic> json)
firstMessageIndex = json['first_message_index']; : firstMessageIndex = json['first_message_index'],
forwardedCount = json['forwarded_count']; forwardedCount = json['forwarded_count'],
isVerified = json['is_verified']; isVerified = json['is_verified'],
sessionData = json['session_data']; sessionData = json['session_data'];
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};
@ -57,10 +56,9 @@ class RoomKeysRoom {
sessions ??= <String, RoomKeysSingleKey>{}; sessions ??= <String, RoomKeysSingleKey>{};
} }
RoomKeysRoom.fromJson(Map<String, dynamic> json) { RoomKeysRoom.fromJson(Map<String, dynamic> json)
sessions = (json['sessions'] as Map) : sessions = (json['sessions'] as Map)
.map((k, v) => MapEntry(k, RoomKeysSingleKey.fromJson(v))); .map((k, v) => MapEntry(k, RoomKeysSingleKey.fromJson(v)));
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};
@ -76,10 +74,9 @@ class RoomKeys {
rooms ??= <String, RoomKeysRoom>{}; rooms ??= <String, RoomKeysRoom>{};
} }
RoomKeys.fromJson(Map<String, dynamic> json) { RoomKeys.fromJson(Map<String, dynamic> json)
rooms = (json['rooms'] as Map) : rooms = (json['rooms'] as Map)
.map((k, v) => MapEntry(k, RoomKeysRoom.fromJson(v))); .map((k, v) => MapEntry(k, RoomKeysRoom.fromJson(v)));
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};
@ -92,10 +89,9 @@ class RoomKeysUpdateResponse {
String etag; String etag;
int count; int count;
RoomKeysUpdateResponse.fromJson(Map<String, dynamic> json) { RoomKeysUpdateResponse.fromJson(Map<String, dynamic> json)
etag = json['etag']; // synapse replies an int but docs say string? : etag = json['etag'], // synapse replies an int but docs say string?
count = json['count']; count = json['count'];
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -25,12 +25,13 @@ class RoomSummary {
List<String> mHeroes; List<String> mHeroes;
int mJoinedMemberCount; int mJoinedMemberCount;
int mInvitedMemberCount; int mInvitedMemberCount;
RoomSummary.fromJson(Map<String, dynamic> json) { RoomSummary.fromJson(Map<String, dynamic> json)
mHeroes = : mHeroes = json['m.heroes'] != null
json['m.heroes'] != null ? List<String>.from(json['m.heroes']) : null; ? List<String>.from(json['m.heroes'])
mJoinedMemberCount = json['m.joined_member_count']; : null,
mInvitedMemberCount = json['m.invited_member_count']; mJoinedMemberCount = json['m.joined_member_count'],
} mInvitedMemberCount = json['m.invited_member_count'];
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};
if (mHeroes != null) { if (mHeroes != null) {

View File

@ -30,17 +30,16 @@ class ServerCapabilities {
MRoomVersions mRoomVersions; MRoomVersions mRoomVersions;
Map<String, dynamic> customCapabilities; Map<String, dynamic> customCapabilities;
ServerCapabilities.fromJson(Map<String, dynamic> json) { ServerCapabilities.fromJson(Map<String, dynamic> json)
mChangePassword = json['m.change_password'] != null : mChangePassword = json['m.change_password'] != null
? MChangePassword.fromJson(json['m.change_password']) ? MChangePassword.fromJson(json['m.change_password'])
: null; : null,
mRoomVersions = json['m.room_versions'] != null mRoomVersions = json['m.room_versions'] != null
? MRoomVersions.fromJson(json['m.room_versions']) ? MRoomVersions.fromJson(json['m.room_versions'])
: null; : null,
customCapabilities = json.copy() customCapabilities = json.copy()
..remove('m.change_password') ..remove('m.change_password')
..remove('m.room_versions'); ..remove('m.room_versions');
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -28,9 +28,8 @@ class StrippedStateEvent extends BasicEventWithSender {
StrippedStateEvent(); StrippedStateEvent();
StrippedStateEvent.fromJson(Map<String, dynamic> json) StrippedStateEvent.fromJson(Map<String, dynamic> json)
: super.fromJson(json) { : stateKey = json['state_key'],
stateKey = json['state_key']; super.fromJson(json);
}
@override @override
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {

View File

@ -28,16 +28,15 @@ class SupportedProtocol {
Map<String, ProtocolFieldType> fieldTypes; Map<String, ProtocolFieldType> fieldTypes;
List<ProtocolInstance> instances; List<ProtocolInstance> instances;
SupportedProtocol.fromJson(Map<String, dynamic> json) { SupportedProtocol.fromJson(Map<String, dynamic> json)
userFields = json['user_fields'].cast<String>(); : userFields = json['user_fields'].cast<String>(),
locationFields = json['location_fields'].cast<String>(); locationFields = json['location_fields'].cast<String>(),
icon = json['icon']; icon = json['icon'],
fieldTypes = (json['field_types'] as Map) fieldTypes = (json['field_types'] as Map)
.map((k, v) => MapEntry(k, ProtocolFieldType.fromJson(v))); .map((k, v) => MapEntry(k, ProtocolFieldType.fromJson(v))),
instances = (json['instances'] as List) instances = (json['instances'] as List)
.map((v) => ProtocolInstance.fromJson(v)) .map((v) => ProtocolInstance.fromJson(v))
.toList(); .toList();
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -25,10 +25,10 @@ class SupportedVersions {
List<String> versions; List<String> versions;
Map<String, bool> unstableFeatures; Map<String, bool> unstableFeatures;
SupportedVersions.fromJson(Map<String, dynamic> json) { SupportedVersions.fromJson(Map<String, dynamic> json)
versions = json['versions'].cast<String>(); : versions = json['versions'].cast<String>(),
unstableFeatures = Map<String, bool>.from(json['unstable_features'] ?? {}); unstableFeatures =
} Map<String, bool>.from(json['unstable_features'] ?? {});
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -41,39 +41,42 @@ class SyncUpdate {
SyncUpdate(); SyncUpdate();
SyncUpdate.fromJson(Map<String, dynamic> json) { SyncUpdate.fromJson(Map<String, dynamic> json)
nextBatch = json['next_batch']; : nextBatch = json['next_batch'],
rooms = json['rooms'] != null ? RoomsUpdate.fromJson(json['rooms']) : null; rooms =
presence = (json['presence'] != null && json['presence']['events'] != null) json['rooms'] != null ? RoomsUpdate.fromJson(json['rooms']) : null,
? (json['presence']['events'] as List) presence =
.map((i) => Presence.fromJson(i)) (json['presence'] != null && json['presence']['events'] != null)
.toList() ? (json['presence']['events'] as List)
: null; .map((i) => Presence.fromJson(i))
accountData = .toList()
(json['account_data'] != null && json['account_data']['events'] != null) : null,
accountData = (json['account_data'] != null &&
json['account_data']['events'] != null)
? (json['account_data']['events'] as List) ? (json['account_data']['events'] as List)
.map((i) => BasicEvent.fromJson(i)) .map((i) => BasicEvent.fromJson(i))
.toList() .toList()
: null,
toDevice =
(json['to_device'] != null && json['to_device']['events'] != null)
? (json['to_device']['events'] as List)
.map((i) => BasicEventWithSender.fromJson(i))
.toList()
: null,
deviceLists = json['device_lists'] != null
? DeviceListsUpdate.fromJson(json['device_lists'])
: null,
deviceOneTimeKeysCount = json['device_one_time_keys_count'] != null
? Map<String, int>.from(json['device_one_time_keys_count'])
: null,
deviceUnusedFallbackKeyTypes = (json[
'device_unused_fallback_key_types'] ??
json[
'org.matrix.msc2732.device_unused_fallback_key_types']) !=
null
? List<String>.from(json['device_unused_fallback_key_types'] ??
json['org.matrix.msc2732.device_unused_fallback_key_types'])
: null; : null;
toDevice =
(json['to_device'] != null && json['to_device']['events'] != null)
? (json['to_device']['events'] as List)
.map((i) => BasicEventWithSender.fromJson(i))
.toList()
: null;
deviceLists = json['device_lists'] != null
? DeviceListsUpdate.fromJson(json['device_lists'])
: null;
deviceOneTimeKeysCount = json['device_one_time_keys_count'] != null
? Map<String, int>.from(json['device_one_time_keys_count'])
: null;
deviceUnusedFallbackKeyTypes = (json['device_unused_fallback_key_types'] ??
json['org.matrix.msc2732.device_unused_fallback_key_types']) !=
null
? List<String>.from(json['device_unused_fallback_key_types'] ??
json['org.matrix.msc2732.device_unused_fallback_key_types'])
: null;
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -24,9 +24,8 @@
class Tag { class Tag {
double order; double order;
Tag.fromJson(Map<String, dynamic> json) { Tag.fromJson(Map<String, dynamic> json)
order = double.tryParse(json['order'].toString()); : order = double.tryParse(json['order'].toString());
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -29,13 +29,12 @@ class ThirdPartyIdentifier {
int validatedAt; int validatedAt;
int addedAt; int addedAt;
ThirdPartyIdentifier.fromJson(Map<String, dynamic> json) { ThirdPartyIdentifier.fromJson(Map<String, dynamic> json)
medium = ThirdPartyIdentifierMedium.values : medium = ThirdPartyIdentifierMedium.values
.firstWhere((medium) => describeEnum(medium) == json['medium']); .firstWhere((medium) => describeEnum(medium) == json['medium']),
address = json['address']; address = json['address'],
validatedAt = json['validated_at']; validatedAt = json['validated_at'],
addedAt = json['added_at']; addedAt = json['added_at'];
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -28,11 +28,10 @@ class ThirdPartyLocation {
String protocol; String protocol;
Map<String, dynamic> fields; Map<String, dynamic> fields;
ThirdPartyLocation.fromJson(Map<String, dynamic> json) { ThirdPartyLocation.fromJson(Map<String, dynamic> json)
alias = json['alias']; : alias = json['alias'],
protocol = json['protocol']; protocol = json['protocol'],
fields = (json['fields'] as Map<String, dynamic>).copy(); fields = (json['fields'] as Map<String, dynamic>).copy();
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -28,11 +28,10 @@ class ThirdPartyUser {
String protocol; String protocol;
Map<String, dynamic> fields; Map<String, dynamic> fields;
ThirdPartyUser.fromJson(Map<String, dynamic> json) { ThirdPartyUser.fromJson(Map<String, dynamic> json)
userId = json['userid']; : userId = json['userid'],
protocol = json['protocol']; protocol = json['protocol'],
fields = (json['fields'] as Map<String, dynamic>).copy(); fields = (json['fields'] as Map<String, dynamic>).copy();
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -29,16 +29,19 @@ class TimelineHistoryResponse {
List<MatrixEvent> chunk; List<MatrixEvent> chunk;
List<MatrixEvent> state; List<MatrixEvent> state;
TimelineHistoryResponse.fromJson(Map<String, dynamic> json) { TimelineHistoryResponse.fromJson(Map<String, dynamic> json)
start = json['start']; : start = json['start'],
end = json['end']; end = json['end'],
chunk = json['chunk'] != null chunk = json['chunk'] != null
? (json['chunk'] as List).map((i) => MatrixEvent.fromJson(i)).toList() ? (json['chunk'] as List)
: null; .map((i) => MatrixEvent.fromJson(i))
state = json['state'] != null .toList()
? (json['state'] as List).map((i) => MatrixEvent.fromJson(i)).toList() : null,
: null; state = json['state'] != null
} ? (json['state'] as List)
.map((i) => MatrixEvent.fromJson(i))
.toList()
: null;
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -27,12 +27,11 @@ class TurnServerCredentials {
List<String> uris; List<String> uris;
num ttl; num ttl;
TurnServerCredentials.fromJson(Map<String, dynamic> json) { TurnServerCredentials.fromJson(Map<String, dynamic> json)
username = json['username']; : username = json['username'],
password = json['password']; password = json['password'],
uris = json['uris'].cast<String>(); uris = json['uris'].cast<String>(),
ttl = json['ttl']; ttl = json['ttl'];
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -26,19 +26,18 @@ import 'matrix_exception.dart';
class UploadKeySignaturesResponse { class UploadKeySignaturesResponse {
Map<String, Map<String, MatrixException>> failures; Map<String, Map<String, MatrixException>> failures;
UploadKeySignaturesResponse.fromJson(Map<String, dynamic> json) { UploadKeySignaturesResponse.fromJson(Map<String, dynamic> json)
failures = json['failures'] != null : failures = json['failures'] != null
? (json['failures'] as Map).map( ? (json['failures'] as Map).map(
(k, v) => MapEntry( (k, v) => MapEntry(
k, k,
(v as Map).map((k, v) => MapEntry( (v as Map).map((k, v) => MapEntry(
k, k,
MatrixException.fromJson(v), MatrixException.fromJson(v),
)), )),
), ),
) )
: null; : null;
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -27,11 +27,10 @@ class UserSearchResult {
List<Profile> results; List<Profile> results;
bool limited; bool limited;
UserSearchResult.fromJson(Map<String, dynamic> json) { UserSearchResult.fromJson(Map<String, dynamic> json)
results = : results =
(json['results'] as List).map((v) => Profile.fromJson(v)).toList(); (json['results'] as List).map((v) => Profile.fromJson(v)).toList(),
limited = json['limited']; limited = json['limited'];
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};

View File

@ -28,18 +28,23 @@ class WellKnownInformation {
MHomeserver mIdentityServer; MHomeserver mIdentityServer;
Map<String, dynamic> content; Map<String, dynamic> content;
WellKnownInformation.fromJson(Map<String, dynamic> json) { factory WellKnownInformation.fromJson(Map<String, dynamic> json) =>
content = json; WellKnownInformation._fromJson(
final mHomeserverMap = json.tryGetMap<String, dynamic>('m.homeserver'); json,
if (mHomeserverMap != null) { json.tryGetMap<String, dynamic>('m.homeserver'),
mHomeserver = MHomeserver.fromJson(mHomeserverMap); json.tryGetMap<String, dynamic>('m.identity_server'));
}
final mIdentityServerMap = WellKnownInformation._fromJson(
json.tryGetMap<String, dynamic>('m.identity_server'); Map<String, dynamic> json,
if (mIdentityServerMap != null) { Map<String, dynamic> mHomeserverMap,
mIdentityServer = MHomeserver.fromJson(mIdentityServerMap); Map<String, dynamic> mIdentityServerMap)
} : content = json,
} mHomeserver = mHomeserverMap != null
? MHomeserver.fromJson(mHomeserverMap)
: null,
mIdentityServer = mIdentityServerMap != null
? MHomeserver.fromJson(mIdentityServerMap)
: null;
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = content; final data = content;

View File

@ -25,13 +25,12 @@ class WhoIsInfo {
String userId; String userId;
Map<String, DeviceInfo> devices; Map<String, DeviceInfo> devices;
WhoIsInfo.fromJson(Map<String, dynamic> json) { WhoIsInfo.fromJson(Map<String, dynamic> json)
userId = json['user_id']; : userId = json['user_id'],
devices = json['devices'] != null devices = json['devices'] != null
? (json['devices'] as Map) ? (json['devices'] as Map)
.map((k, v) => MapEntry(k, DeviceInfo.fromJson(v))) .map((k, v) => MapEntry(k, DeviceInfo.fromJson(v)))
: null; : null;
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final data = <String, dynamic>{}; final data = <String, dynamic>{};