68 lines
1.9 KiB
Dart
68 lines
1.9 KiB
Dart
/// Modelo de usuario para el pool de usuarios en modo multi-dispositivo
|
|
class Usuario {
|
|
final String id;
|
|
final String nombre;
|
|
final String? nick;
|
|
final String? avatar;
|
|
final String? foto;
|
|
final String? creadoPorClienteId;
|
|
final String? clienteIdSeleccionado;
|
|
|
|
Usuario({
|
|
required this.id,
|
|
required this.nombre,
|
|
this.nick,
|
|
this.avatar,
|
|
this.foto,
|
|
this.creadoPorClienteId,
|
|
this.clienteIdSeleccionado,
|
|
});
|
|
|
|
bool get estaSeleccionado => clienteIdSeleccionado != null;
|
|
bool get estaDisponible => clienteIdSeleccionado == null;
|
|
|
|
Usuario copiar({
|
|
String? id,
|
|
String? nombre,
|
|
String? nick,
|
|
String? avatar,
|
|
String? foto,
|
|
String? creadoPorClienteId,
|
|
String? clienteIdSeleccionado,
|
|
bool liberarSeleccion = false,
|
|
}) {
|
|
return Usuario(
|
|
id: id ?? this.id,
|
|
nombre: nombre ?? this.nombre,
|
|
nick: nick ?? this.nick,
|
|
avatar: avatar ?? this.avatar,
|
|
foto: foto ?? this.foto,
|
|
creadoPorClienteId: creadoPorClienteId ?? this.creadoPorClienteId,
|
|
clienteIdSeleccionado: liberarSeleccion
|
|
? null
|
|
: (clienteIdSeleccionado ?? this.clienteIdSeleccionado),
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
'id': id,
|
|
'nombre': nombre,
|
|
if (nick != null) 'nick': nick,
|
|
if (avatar != null) 'avatar': avatar,
|
|
if (foto != null) 'foto': foto,
|
|
if (creadoPorClienteId != null) 'creadoPorClienteId': creadoPorClienteId,
|
|
if (clienteIdSeleccionado != null)
|
|
'clienteIdSeleccionado': clienteIdSeleccionado,
|
|
};
|
|
|
|
factory Usuario.fromJson(Map<String, dynamic> json) => Usuario(
|
|
id: json['id'] as String,
|
|
nombre: json['nombre'] as String,
|
|
nick: json['nick'] as String?,
|
|
avatar: json['avatar'] as String?,
|
|
foto: json['foto'] as String?,
|
|
creadoPorClienteId: json['creadoPorClienteId'] as String?,
|
|
clienteIdSeleccionado: json['clienteIdSeleccionado'] as String?,
|
|
);
|
|
}
|