update user model

This commit is contained in:
Salvatore Giordano
2021-04-20 11:07:55 +02:00
parent 228778f2b1
commit 629691ad5b
3 changed files with 6 additions and 19 deletions
@@ -23,7 +23,7 @@ OwnUser _$OwnUserFromJson(Map<String, dynamic> 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),
+4 -17
View File
@@ -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<String, dynamic> 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(
@@ -9,7 +9,7 @@ part of 'user.dart';
User _$UserFromJson(Map<String, dynamic> 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),