Mejora flujo de datos en partidas multidispositivos
This commit is contained in:
@@ -130,41 +130,7 @@ class _PantallaResultadoState extends State<PantallaResultado>
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Detalle de votos
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(l10n.votesThisRound,
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.titleMedium),
|
||||
const SizedBox(height: 8),
|
||||
...widget.resultado.votos.entries.map((e) {
|
||||
final votante = partida?.jugadores
|
||||
.firstWhere((j) => j.id == e.key);
|
||||
final votado = partida?.jugadores
|
||||
.firstWhere((j) => j.id == e.value);
|
||||
return Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: 2),
|
||||
child: Text(
|
||||
'${votante?.nombre ?? '?'} → ${votado?.nombre ?? '?'}',
|
||||
style: TextStyle(
|
||||
color: e.value ==
|
||||
widget.resultado.eliminadoId
|
||||
? TemaApp.colorAcento
|
||||
: TemaApp.colorTextoSecundario,
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildDetalleVotos(context, partida, l10n),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Acciones
|
||||
@@ -181,6 +147,139 @@ class _PantallaResultadoState extends State<PantallaResultado>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDetalleVotos(
|
||||
BuildContext context,
|
||||
Partida? partida,
|
||||
AppLocalizations l10n,
|
||||
) {
|
||||
final jugadores = {
|
||||
for (final jugador in partida?.jugadores ?? []) jugador.id: jugador,
|
||||
};
|
||||
final conteo = <String, int>{};
|
||||
for (final votadoId in widget.resultado.votos.values) {
|
||||
conteo[votadoId] = (conteo[votadoId] ?? 0) + 1;
|
||||
}
|
||||
final maxVotos = conteo.values.isEmpty
|
||||
? 1
|
||||
: conteo.values.reduce((a, b) => a > b ? a : b);
|
||||
final ranking = conteo.entries.toList()
|
||||
..sort((a, b) => b.value.compareTo(a.value));
|
||||
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.bar_chart, color: TemaApp.colorNaranja),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
l10n.votesThisRound,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
...ranking.map((entry) {
|
||||
final jugador = jugadores[entry.key];
|
||||
final eliminado = entry.key == widget.resultado.eliminadoId;
|
||||
return _buildBarraVotos(
|
||||
context,
|
||||
nombre: jugador?.nombre ?? '?',
|
||||
votos: entry.value,
|
||||
total: maxVotos,
|
||||
destacado: eliminado,
|
||||
);
|
||||
}),
|
||||
const Divider(height: 24),
|
||||
...widget.resultado.votos.entries.map((entry) {
|
||||
final votante = jugadores[entry.key]?.nombre ?? '?';
|
||||
final votado = jugadores[entry.value]?.nombre ?? '?';
|
||||
final fueAlEliminado =
|
||||
entry.value == widget.resultado.eliminadoId;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
fueAlEliminado
|
||||
? Icons.how_to_vote
|
||||
: Icons.arrow_forward,
|
||||
size: 18,
|
||||
color: fueAlEliminado
|
||||
? TemaApp.colorAcento
|
||||
: TemaApp.colorTextoSecundario,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'$votante → $votado',
|
||||
style: TextStyle(
|
||||
color: fueAlEliminado
|
||||
? TemaApp.colorTexto
|
||||
: TemaApp.colorTextoSecundario,
|
||||
fontWeight: fueAlEliminado
|
||||
? FontWeight.bold
|
||||
: FontWeight.normal,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBarraVotos(
|
||||
BuildContext context, {
|
||||
required String nombre,
|
||||
required int votos,
|
||||
required int total,
|
||||
required bool destacado,
|
||||
}) {
|
||||
final color = destacado ? TemaApp.colorAcento : TemaApp.colorNaranja;
|
||||
final proporcion = total == 0 ? 0.0 : votos / total;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
nombre,
|
||||
style: TextStyle(
|
||||
fontWeight: destacado ? FontWeight.bold : FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'$votos',
|
||||
style: TextStyle(color: color, fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
child: LinearProgressIndicator(
|
||||
value: proporcion.clamp(0.0, 1.0).toDouble(),
|
||||
minHeight: 10,
|
||||
backgroundColor: TemaApp.colorSuperficie,
|
||||
valueColor: AlwaysStoppedAnimation(color),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
Widget _construirBotones(BuildContext context, EstadoJuego estado) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final partida = estado.partida;
|
||||
|
||||
Reference in New Issue
Block a user