added null safety for llc

This commit is contained in:
Deven Joshi
2021-04-08 15:03:16 +05:30
parent 3a5308a9c0
commit c80fc0a6b4
41 changed files with 1222 additions and 1202 deletions
+23 -23
View File
@@ -20,8 +20,8 @@ class User {
});
/// Create a new instance from a json
factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(
Serialization.moveToExtraDataFromRoot(json, topLevelFields));
factory User.fromJson(Map<String, dynamic>? json) => _$UserFromJson(
Serialization.moveToExtraDataFromRoot(json, topLevelFields)!);
/// Use this named constructor to create a new user instance
User.init(
@@ -49,47 +49,47 @@ class User {
];
/// User id
final String id;
final String? id;
/// User role
@JsonKey(includeIfNull: false, toJson: Serialization.readOnly)
final String role;
final String? role;
/// User role
@JsonKey(includeIfNull: false, toJson: Serialization.readOnly)
final List<String> teams;
final List<String>? teams;
/// Date of user creation
@JsonKey(includeIfNull: false, toJson: Serialization.readOnly)
final DateTime createdAt;
final DateTime? createdAt;
/// Date of last user update
@JsonKey(includeIfNull: false, toJson: Serialization.readOnly)
final DateTime updatedAt;
final DateTime? updatedAt;
/// Date of last user connection
@JsonKey(includeIfNull: false, toJson: Serialization.readOnly)
final DateTime lastActive;
final DateTime? lastActive;
/// True if user is online
@JsonKey(includeIfNull: false, toJson: Serialization.readOnly)
final bool online;
final bool? online;
/// True if user is banned from the chat
@JsonKey(includeIfNull: false, toJson: Serialization.readOnly)
final bool banned;
final bool? banned;
/// Map of custom user extraData
@JsonKey(includeIfNull: false)
final Map<String, dynamic> extraData;
final Map<String, dynamic>? extraData;
@override
int get hashCode => id.hashCode;
/// Shortcut for user name
String get name =>
(extraData?.containsKey('name') == true && extraData['name'] != '')
? extraData['name']
String? get name =>
(extraData?.containsKey('name') == true && extraData!['name'] != '')
? extraData!['name']
: id;
@override
@@ -103,15 +103,15 @@ class User {
/// Creates a copy of [User] with specified attributes overridden.
User copyWith({
String id,
String role,
DateTime createdAt,
DateTime updatedAt,
DateTime lastActive,
bool online,
Map<String, dynamic> extraData,
bool banned,
List<String> teams,
String? id,
String? role,
DateTime? createdAt,
DateTime? updatedAt,
DateTime? lastActive,
bool? online,
Map<String, dynamic>? extraData,
bool? banned,
List<String>? teams,
}) =>
User(
id: id ?? this.id,