refactorización de pantallas

This commit is contained in:
2026-05-11 23:16:38 +02:00
parent 1929d86689
commit 4599678e77
48 changed files with 1446 additions and 1463 deletions
+136 -190
View File
@@ -1,4 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter/material.dart';
import 'package:farolero/l10n/generated/app_localizations.dart';
import 'package:provider/provider.dart';
import '../estado/estado_juego.dart';
@@ -30,6 +30,22 @@ class _PantallaAdivinanzaState extends State<PantallaAdivinanza> {
setState(() => _acierto = resultado);
}
void _continuarTrasNoAdivinar(EstadoJuego estado) {
final fin = estado.comprobarFinPartida();
if (fin) {
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (_) => const PantallaFinPartida()),
);
} else {
estado.siguienteRonda();
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (_) => const PantallaDebate()),
);
}
}
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context)!;
@@ -44,199 +60,129 @@ class _PantallaAdivinanzaState extends State<PantallaAdivinanza> {
),
body: FondoFarolero(
intenso: true,
child: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.all(32),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const ArteGameplayFarolero.fase(height: 132),
const SizedBox(height: 12),
EncabezadoFarolero(
icono: Icons.theater_comedy,
titulo: l10n.impostorCanGuess,
subtitulo: l10n.ifCorrectImpostorsWin,
color: TemaApp.colorAcento,
trailing: Image.asset(
'assets/ui/generated/meta/result_verdict_art.webp',
width: 42,
height: 42,
opacity: const AlwaysStoppedAnimation(0.64),
),
child: SafeArea(
child: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const ArteGameplayFarolero.fase(height: 132),
const SizedBox(height: 12),
TarjetaFaseFarolero(
icono: Icons.theater_comedy,
titulo: l10n.impostorCanGuess,
subtitulo: l10n.ifCorrectImpostorsWin,
color: TemaApp.colorAcento,
child: _buildContenido(context, l10n, estado, partida.palabraSecreta),
),
],
),
const SizedBox(height: 32),
if (_acierto == null) ...[
TextField(
controller: _controlador,
decoration: InputDecoration(
hintText: l10n.guessWordHint,
prefixIcon: const Icon(Icons.search),
),
textCapitalization: TextCapitalization.sentences,
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 20),
onSubmitted: (_) => _intentarAdivinar(),
),
const SizedBox(height: 24),
Row(
children: [
Expanded(
child: OutlinedButton(
onPressed: () {
// No intenta adivinar, siguiente ronda
final fin = estado.comprobarFinPartida();
if (fin) {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (_) => const PantallaFinPartida(),
),
);
} else {
estado.siguienteRonda();
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (_) => const PantallaDebate(),
),
);
}
},
child: Text(l10n.dontGuess),
),
),
const SizedBox(width: 12),
Expanded(
flex: 2,
child: ElevatedButton.icon(
onPressed: _controlador.text.trim().isNotEmpty
? _intentarAdivinar
: null,
icon: const Icon(Icons.send),
label: Text(l10n.guess),
),
),
],
),
],
if (_acierto == true) ...[
const SizedBox(height: 16),
Container(
padding: const EdgeInsets.all(24),
decoration: BoxDecoration(
color: TemaApp.colorAcento.withValues(alpha: 0.3),
borderRadius: BorderRadius.circular(16),
border: Border.all(color: TemaApp.colorAcento),
),
child: Column(
children: [
const Text('🎭🎉', style: TextStyle(fontSize: 48)),
const SizedBox(height: 12),
Text(
l10n.correctGuess,
style: Theme.of(context)
.textTheme
.headlineMedium
?.copyWith(color: TemaApp.colorAcento),
),
const SizedBox(height: 8),
Text(
l10n.theWordWas(partida.palabraSecreta),
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: 8),
Text(
l10n.impostorsWin,
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
color: TemaApp.colorNaranja,
),
),
],
),
),
const SizedBox(height: 24),
SizedBox(
width: double.infinity,
height: 56,
child: ElevatedButton.icon(
onPressed: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (_) => const PantallaFinPartida(),
),
);
},
icon: const Icon(Icons.emoji_events),
label: Text(l10n.seeEndResult),
),
),
],
if (_acierto == false) ...[
const SizedBox(height: 16),
Container(
padding: const EdgeInsets.all(24),
decoration: BoxDecoration(
color: TemaApp.colorVerde.withValues(alpha: 0.3),
borderRadius: BorderRadius.circular(16),
border: Border.all(color: TemaApp.colorVerde),
),
child: Column(
children: [
const Text('', style: TextStyle(fontSize: 48)),
const SizedBox(height: 12),
Text(
l10n.wrongGuess,
style: Theme.of(context)
.textTheme
.headlineMedium
?.copyWith(color: TemaApp.colorVerde),
),
const SizedBox(height: 8),
Text(
l10n.gameContinues,
style: Theme.of(context).textTheme.bodyLarge,
),
],
),
),
const SizedBox(height: 24),
SizedBox(
width: double.infinity,
height: 56,
child: ElevatedButton.icon(
onPressed: () {
final fin = estado.comprobarFinPartida();
if (fin) {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (_) => const PantallaFinPartida(),
),
);
} else {
estado.siguienteRonda();
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (_) => const PantallaDebate(),
),
);
}
},
icon: const Icon(Icons.skip_next),
label: Text(l10n.nextRound),
),
),
],
],
),
),
),
),
),
);
}
Widget _buildContenido(
BuildContext context,
AppLocalizations l10n,
EstadoJuego estado,
String palabraSecreta,
) {
if (_acierto == null) {
return Column(
children: [
TextField(
controller: _controlador,
decoration: InputDecoration(
hintText: l10n.guessWordHint,
prefixIcon: const Icon(Icons.search),
),
textCapitalization: TextCapitalization.sentences,
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 20),
onChanged: (value) => setState(() {}),
onSubmitted: (value) => _intentarAdivinar(),
),
const SizedBox(height: 24),
Row(
children: [
Expanded(
child: BotonFarolero.oscuro(
texto: l10n.dontGuess,
icono: Icons.skip_next,
onPressed: () => _continuarTrasNoAdivinar(estado),
),
),
const SizedBox(width: 12),
Expanded(
flex: 2,
child: BotonFarolero(
texto: l10n.guess,
icono: Icons.send,
onPressed: _controlador.text.trim().isNotEmpty ? _intentarAdivinar : null,
),
),
],
),
],
);
}
final acierto = _acierto == true;
final color = acierto ? TemaApp.colorAcento : TemaApp.colorVerde;
return Column(
children: [
PanelFarolero(
padding: const EdgeInsets.all(24),
borderColor: color,
color: color.withValues(alpha: 0.18),
child: Column(
children: [
Icon(
acierto ? Icons.celebration : Icons.cancel,
color: color,
size: 52,
),
const SizedBox(height: 12),
Text(
acierto ? l10n.correctGuess : l10n.wrongGuess,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.headlineMedium?.copyWith(color: color),
),
const SizedBox(height: 8),
Text(
acierto ? l10n.theWordWas(palabraSecreta) : l10n.gameContinues,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.titleLarge,
),
if (acierto) ...[
const SizedBox(height: 8),
Text(
l10n.impostorsWin,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyLarge?.copyWith(color: TemaApp.colorNaranja),
),
],
],
),
),
const SizedBox(height: 24),
BotonFarolero(
texto: acierto ? l10n.seeEndResult : l10n.nextRound,
icono: acierto ? Icons.emoji_events : Icons.skip_next,
onPressed: acierto
? () {
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (_) => const PantallaFinPartida()),
);
}
: () => _continuarTrasNoAdivinar(estado),
),
],
);
}
}