82 lines
2.4 KiB
Dart
82 lines
2.4 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;
|
|
final int fuego;
|
|
final List<String> medallas;
|
|
|
|
Usuario({
|
|
required this.id,
|
|
required this.nombre,
|
|
this.nick,
|
|
this.avatar,
|
|
this.foto,
|
|
this.creadoPorClienteId,
|
|
this.clienteIdSeleccionado,
|
|
this.fuego = 0,
|
|
this.medallas = const [],
|
|
});
|
|
|
|
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,
|
|
int? fuego,
|
|
List<String>? medallas,
|
|
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),
|
|
fuego: fuego ?? this.fuego,
|
|
medallas: medallas ?? this.medallas,
|
|
);
|
|
}
|
|
|
|
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,
|
|
if (fuego > 0) 'fuego': fuego,
|
|
if (medallas.isNotEmpty) 'medallas': medallas,
|
|
};
|
|
|
|
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?,
|
|
fuego: (json['fuego'] as num?)?.toInt() ?? 0,
|
|
medallas: (json['medallas'] as List<dynamic>? ?? const [])
|
|
.map((valor) => valor.toString())
|
|
.toList(),
|
|
);
|
|
}
|