From 629691ad5b8684ba1498ad94298991032ad344d5 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Tue, 20 Apr 2021 11:07:55 +0200 Subject: [PATCH] update user model --- .../lib/src/models/own_user.g.dart | 2 +- packages/stream_chat/lib/src/models/user.dart | 21 ++++--------------- .../stream_chat/lib/src/models/user.g.dart | 2 +- 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/packages/stream_chat/lib/src/models/own_user.g.dart b/packages/stream_chat/lib/src/models/own_user.g.dart index 5802060c..785efb04 100644 --- a/packages/stream_chat/lib/src/models/own_user.g.dart +++ b/packages/stream_chat/lib/src/models/own_user.g.dart @@ -23,7 +23,7 @@ OwnUser _$OwnUserFromJson(Map json) { .toList() ?? [], id: json['id'] as String, - role: json['role'] as String? ?? '', + role: json['role'] as String, createdAt: json['created_at'] == null ? null : DateTime.parse(json['created_at'] as String), diff --git a/packages/stream_chat/lib/src/models/user.dart b/packages/stream_chat/lib/src/models/user.dart index 67fc99f0..8b965589 100644 --- a/packages/stream_chat/lib/src/models/user.dart +++ b/packages/stream_chat/lib/src/models/user.dart @@ -8,8 +8,8 @@ part 'user.g.dart'; class User { /// Constructor used for json serialization User({ - this.id = '', - this.role = '', + required this.id, + this.role, DateTime? createdAt, DateTime? updatedAt, this.lastActive, @@ -24,18 +24,6 @@ class User { factory User.fromJson(Map json) => _$UserFromJson( Serialization.moveToExtraDataFromRoot(json, topLevelFields)); - /// Use this named constructor to create a new user instance - User.init( - this.id, { - this.online = false, - this.extraData = const {}, - required this.createdAt, - required this.updatedAt, - this.teams = const [], - required this.role, - }) : lastActive = null, - banned = false; - /// Known top level fields. /// Useful for [Serialization] methods. static const topLevelFields = [ @@ -53,9 +41,8 @@ class User { final String id; /// User role - @JsonKey( - includeIfNull: false, toJson: Serialization.readOnly, defaultValue: '') - final String role; + @JsonKey(includeIfNull: false, toJson: Serialization.readOnly) + final String? role; /// User role @JsonKey( diff --git a/packages/stream_chat/lib/src/models/user.g.dart b/packages/stream_chat/lib/src/models/user.g.dart index 18408d76..ef1ccf77 100644 --- a/packages/stream_chat/lib/src/models/user.g.dart +++ b/packages/stream_chat/lib/src/models/user.g.dart @@ -9,7 +9,7 @@ part of 'user.dart'; User _$UserFromJson(Map json) { return User( id: json['id'] as String, - role: json['role'] as String? ?? '', + role: json['role'] as String?, createdAt: json['created_at'] == null ? null : DateTime.parse(json['created_at'] as String),