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 optional name argument is provided in the constructor then it will be set on extraData with a key of 'name'.

final channel = Channel(client, type, id, name: 'Channel name');
print(channel.name == channel.extraData['name']); // true

Before the channel is initialized the name can be set directly:

channel.name = 'New channel name';

To update the name after the channel has been initialized, call:

channel.updateName('Updated channel name');

This will do a partial update to update the name.

If an optional image argument is provided in the constructor then it will be set on extraData with a key of 'image'.

final channel = Channel(client, type, id, image: 'https://getstream.io/image.png');
print(channel.image == channel.extraData['image']); // true

Before the channel is initialized the image can be set directly:

channel.image = 'https://getstream.io/new-image';

To update the image after the channel has been initialized, call:

channel.updateImage('https://getstream.io/new-image');

This will do a partial update to update the image.

Implementation

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