Files
farolero/lib/pantallas/pantalla_resultado_online.dart
T
FreeTLab 56f07364c2
Build & Deploy Farolero / Análisis de código (push) Successful in 13s
Build & Deploy Farolero / Build APK + AAB release (push) Successful in 1m22s
feat: confirm before leaving a game, and fix untranslated strings
Exit confirmation
- A dialog in the app's own style now guards every in-game screen. The safe
  action is the prominent one, so a stray tap keeps you in the game.
- Eleven screens covered, against both the system back gesture and the close
  buttons. The message adapts: a single-device game is lost, a host ends it
  for everyone, a client can rejoin.
- The two screens the host also opens from the manager take a flag so that
  back there just closes them instead of offering to quit.

Translations
- 21 keys were still holding the English text in Arabic, Basque, Hindi,
  Japanese, Korean, Dutch, Polish, Russian, Turkish and both Chinese
  variants: 231 strings, covering the whole multi-device flow, permissions
  and the mode picker. Nothing failed, the app just showed English.
- The permissions dialog was hardcoded in Spanish; it is localized now.
- Portuguese used Spanish gerunds where pt-PT takes "a + infinitive".

Checked what looked untranslated but is not: Animals and Notes are correct
Catalan, Configuration and Vibration correct French, Version correct German.
Those are whitelisted in the new test rather than silently rewritten.

l10n_cobertura_test guards all of it: no missing or orphan keys, no empty
values, no English left outside the whitelist, and placeholders preserved.
2026-07-25 23:59:57 +02:00

260 lines
8.0 KiB
Dart

import 'package:flutter/material.dart';
import '../tema/dialogo_confirmacion.dart';
import 'package:farolero/l10n/generated/app_localizations.dart';
import '../modelos/inicio_partida_multijugador.dart';
import '../modelos/snapshot_partida_online.dart';
import '../servicios/servicio_nearby.dart';
import '../tema/componentes_farolero.dart';
import '../tema/componentes_resultado_farolero.dart';
import '../tema/tema_app.dart';
import 'pantalla_debate_cliente.dart';
import 'pantalla_fin_partida_online.dart';
import 'pantalla_notas_online.dart';
import 'pantalla_revision_palabra.dart';
import 'pantalla_votacion_cliente.dart';
import 'package:provider/provider.dart';
class PantallaResultadoOnline extends StatefulWidget {
final SnapshotPartidaOnline snapshot;
final List<JugadorInicioPartida> jugadoresControlados;
final String? pistaImpostor;
const PantallaResultadoOnline({
super.key,
required this.snapshot,
required this.jugadoresControlados,
this.pistaImpostor,
});
@override
State<PantallaResultadoOnline> createState() => _PantallaResultadoOnlineState();
}
class _PantallaResultadoOnlineState extends State<PantallaResultadoOnline> {
OnMensajeCallback? _listener;
ServicioNearby? _nearby;
late SnapshotPartidaOnline _snapshot;
@override
void initState() {
super.initState();
_snapshot = widget.snapshot;
_listener = (endpointId, mensaje) {
if (!mounted) return;
if (mensaje.tipo == TipoMensaje.partidaFin) {
_abrirFin(mensaje.datos);
return;
}
if (mensaje.tipo == TipoMensaje.votacionResultado) {
setState(() => _snapshot = SnapshotPartidaOnline.fromJson(mensaje.datos));
return;
}
if (mensaje.tipo != TipoMensaje.fase) return;
final fase = mensaje.datos['fase'] as String?;
if (fase == 'debate') {
_abrirDebate(mensaje.datos);
} else if (fase == 'votacion') {
_abrirVotacion(mensaje.datos);
} else if (fase == 'adivinanza' || fase == 'resultado') {
setState(() => _snapshot = SnapshotPartidaOnline.fromJson(mensaje.datos));
} else if (fase == 'finPartida') {
_abrirFin(mensaje.datos);
}
};
WidgetsBinding.instance.addPostFrameCallback((_) {
final listener = _listener;
if (listener != null && mounted) {
_nearby = context.read<ServicioNearby>();
_nearby!.onMensaje(listener);
}
});
}
@override
void dispose() {
final listener = _listener;
if (listener != null) {
_nearby?.removeMensajeListener(listener);
}
super.dispose();
}
void _abrirDebate(Map<String, dynamic> datos) {
final snapshot = SnapshotPartidaOnline.fromJson(datos);
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (_) => PantallaDebateCliente(
tiempoDebateSegundos: datos['tiempoDebateSegundos'] as int?,
primerTurnoNombre: datos['primerTurnoNombre'] as String?,
partidaId: snapshot.roomId,
pistaImpostor: widget.pistaImpostor,
jugadores: snapshot.jugadores,
jugadoresControlados: widget.jugadoresControlados,
onSolicitarVotacion: _solicitarVotacion,
),
),
);
}
void _abrirVotacion(Map<String, dynamic> datos) {
final snapshot = SnapshotPartidaOnline.fromJson(datos);
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (_) => PantallaVotacionCliente(
jugadores: snapshot.jugadores,
jugadoresControlados: widget.jugadoresControlados,
partidaId: snapshot.roomId,
pistaImpostor: widget.pistaImpostor,
onVotos: _enviarVotos,
),
),
);
}
void _abrirFin(Map<String, dynamic> datos) {
final snapshot = SnapshotPartidaOnline.fromJson(datos);
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (_) => PantallaFinPartidaOnline(
snapshot: snapshot,
jugadoresControlados: widget.jugadoresControlados,
pistaImpostor: widget.pistaImpostor,
),
),
);
}
void _solicitarVotacion() {
final nearby = context.read<ServicioNearby>();
if (nearby.hostEndpointId == null) return;
nearby.enviarMensaje(
nearby.hostEndpointId!,
MensajeP2P(
tipo: TipoMensaje.ping,
datos: {'solicitoVotacion': true},
),
);
}
void _enviarVotos(Map<String, String> votos) {
final nearby = context.read<ServicioNearby>();
if (nearby.hostEndpointId == null) return;
for (final entry in votos.entries) {
nearby.enviarMensaje(
nearby.hostEndpointId!,
MensajeP2P(
tipo: TipoMensaje.voto,
datos: {
'votanteId': entry.key,
'votadoId': entry.value,
'votoporId': entry.value,
},
),
);
}
}
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context)!;
final resultado = _snapshot.resultadoActual;
return GuardiaSalidaPartida(
contexto: ContextoSalida.cliente,
child: Scaffold(
backgroundColor: TemaApp.colorFondo,
appBar: AppBar(
title: Text(_snapshot.fase == 'adivinanza'
? l10n.impostorGuessTitle
: l10n.result),
automaticallyImplyLeading: false,
backgroundColor: Colors.transparent,
elevation: 0,
actions: _acciones(context, l10n),
),
body: FondoFarolero(
intenso: true,
child: SafeArea(
top: false,
child: SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: resultado == null
? _buildEsperaAdivinanza(context, l10n)
: ResultadoRondaFarolero(
resultado: resultado,
jugadores: _snapshot.jugadores,
mensaje: _snapshot.mensaje,
),
),
),
),
),
);
}
List<Widget> _acciones(BuildContext context, AppLocalizations l10n) => [
IconButton(
tooltip: l10n.seeYourWord,
icon: IconoFarolero(Icons.visibility),
onPressed: widget.jugadoresControlados.isEmpty
? null
: () => mostrarRevisionPalabraOnline(
context: context,
jugadoresControlados: widget.jugadoresControlados,
pistaImpostor: widget.pistaImpostor,
),
),
IconButton(
tooltip: l10n.notesTitle,
icon: IconoFarolero(Icons.edit_note),
onPressed: _snapshot.roomId == null || widget.jugadoresControlados.isEmpty
? null
: () => Navigator.push(
context,
MaterialPageRoute(
builder: (_) => PantallaNotasOnline(
partidaId: _snapshot.roomId!,
jugadores: _snapshot.jugadores,
autoresControlados: widget.jugadoresControlados,
),
),
),
),
];
Widget _buildEsperaAdivinanza(
BuildContext context,
AppLocalizations l10n,
) {
return Center(
child: PanelFarolero(
margin: const EdgeInsets.all(16),
borderColor: TemaApp.colorNaranja.withValues(alpha: 0.48),
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const ArteGameplayFarolero.resultado(height: 142),
const SizedBox(height: 16),
Text(
_snapshot.mensaje ?? l10n.impostorCanGuess,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: 12),
Text(
l10n.waitingForHost,
textAlign: TextAlign.center,
style: TextStyle(color: TemaApp.colorTextoSecundario),
),
],
),
),
),
);
}
}