User constructor

User({
  1. required String id,
  2. String? role,
  3. String? name,
  4. String? image,
  5. DateTime? createdAt,
  6. DateTime? updatedAt,
  7. DateTime? lastActive,
  8. Map<String, Object?> extraData = const {},
  9. bool online = false,
  10. bool banned = false,
  11. DateTime? banExpires,
  12. List<String> teams = const [],
  13. String? language,
})

Creates a new user.

If an name is provided it will be set on extraData with a key of 'name'.

For example:

final user = User(id: 'id', name: 'Sahil Kumar');
print(user.name == user.extraData['name']); // true

If an image is provided it will be set on extraData with a key of 'image'.

For example:

final user = User(id: 'id', image: 'https://getstream.io/image.png');
print(user.image == user.extraData['image']); // true

Implementation

User({
  required this.id,
  this.role,
  String? name,
  String? image,
  this.createdAt,
  this.updatedAt,
  this.lastActive,
  Map<String, Object?> extraData = const {},
  this.online = false,
  this.banned = false,
  this.banExpires,
  this.teams = const [],
  this.language,
}) :
      // For backwards compatibility, set 'name', 'image' in [extraData].
      extraData = {
        ...extraData,
        if (name != null) 'name': name,
        if (image != null) 'image': image,
      };