fix: boton ver palabra del host ahora funciona #3

Merged
FreeTLab merged 1 commits from feat/host-como-jugador into main 2026-04-24 21:37:43 +02:00

View File

@@ -7,7 +7,6 @@ import '../modelos/partida.dart';
import '../servicios/servicio_nearby.dart'; import '../servicios/servicio_nearby.dart';
import '../tema/tema_app.dart'; import '../tema/tema_app.dart';
class PantallaGestorHost extends StatefulWidget { class PantallaGestorHost extends StatefulWidget {
final VoidCallback onPartidaFin; final VoidCallback onPartidaFin;
@@ -253,6 +252,21 @@ class _PantallaGestorHostState extends State<PantallaGestorHost> {
), ),
), ),
const Spacer(), const Spacer(),
// Botón para que el host vea su palabra
SizedBox(
width: double.infinity,
child: ElevatedButton.icon(
onPressed: () => _mostrarPalabraHost(context),
icon: const Icon(Icons.visibility),
label: Text(l10n.seeYourWord),
style: ElevatedButton.styleFrom(
backgroundColor: TemaApp.colorNaranja,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 16),
),
),
),
const SizedBox(height: 12),
if (todosListos) if (todosListos)
Container( Container(
padding: const EdgeInsets.all(12), padding: const EdgeInsets.all(12),
@@ -278,6 +292,31 @@ class _PantallaGestorHostState extends State<PantallaGestorHost> {
); );
} }
void _mostrarPalabraHost(BuildContext context) {
final estado = context.read<EstadoJuego>();
final partida = estado.partida;
if (partida == null) return;
// Buscar el jugador host local
final hostLocal = partida.jugadores.firstWhere(
(j) => j.nombre == context.read<ServicioNearby>().miNombre,
orElse: () => partida.jugadores.first,
);
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => _PantallaRevelarPalabraHost(
nombre: hostLocal.nombre,
esImpostor: hostLocal.esImpostor,
palabra: partida.palabraSecreta,
pistaActiva: partida.config.pistaImpostor,
categoria: partida.categoriaReal,
),
),
);
}
Widget _buildFaseDebate( Widget _buildFaseDebate(
BuildContext context, BuildContext context,
AppLocalizations l10n, AppLocalizations l10n,
@@ -451,7 +490,10 @@ class _PantallaGestorHostState extends State<PantallaGestorHost> {
), ),
child: Row( child: Row(
children: [ children: [
Text(esHost ? '👑' : '🎭', style: const TextStyle(fontSize: 18)), Text(
esHost ? 'Host' : 'Cliente',
style: const TextStyle(fontSize: 18),
),
const SizedBox(width: 8), const SizedBox(width: 8),
Expanded(child: Text(nombre)), Expanded(child: Text(nombre)),
if (listo) if (listo)
@@ -512,3 +554,154 @@ class _PantallaGestorHostState extends State<PantallaGestorHost> {
} }
} }
} }
class _PantallaRevelarPalabraHost extends StatefulWidget {
final String nombre;
final bool esImpostor;
final String palabra;
final bool pistaActiva;
final String categoria;
const _PantallaRevelarPalabraHost({
required this.nombre,
required this.esImpostor,
required this.palabra,
required this.pistaActiva,
required this.categoria,
});
@override
State<_PantallaRevelarPalabraHost> createState() =>
_PantallaRevelarPalabraHostState();
}
class _PantallaRevelarPalabraHostState
extends State<_PantallaRevelarPalabraHost> {
bool _manteniendo = false;
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context)!;
return Scaffold(
appBar: AppBar(title: Text(widget.nombre)),
body: Center(
child: Padding(
padding: const EdgeInsets.all(32),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
widget.nombre,
style: Theme.of(context).textTheme.headlineMedium,
),
const SizedBox(height: 32),
AnimatedContainer(
duration: const Duration(milliseconds: 200),
width: double.infinity,
padding: const EdgeInsets.all(32),
decoration: BoxDecoration(
color: _manteniendo
? (widget.esImpostor
? TemaApp.colorAcento.withValues(alpha: 0.3)
: TemaApp.colorVerde.withValues(alpha: 0.3))
: TemaApp.colorTarjeta,
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: _manteniendo
? (widget.esImpostor
? TemaApp.colorAcento
: TemaApp.colorVerde)
: Colors.transparent,
width: 2,
),
),
child: _manteniendo
? Column(
children: [
Text(
widget.esImpostor ? 'Impostor' : 'Ciudadano',
style: const TextStyle(fontSize: 48),
),
const SizedBox(height: 16),
Text(
widget.esImpostor
? l10n.youAreImpostor
: l10n.yourWordIs,
style: Theme.of(context).textTheme.titleLarge
?.copyWith(
color: widget.esImpostor
? TemaApp.colorAcento
: TemaApp.colorVerde,
),
),
if (!widget.esImpostor) ...[
const SizedBox(height: 12),
Text(
widget.palabra,
style: Theme.of(context).textTheme.headlineLarge
?.copyWith(fontSize: 32, color: Colors.white),
textAlign: TextAlign.center,
),
],
if (widget.esImpostor && widget.pistaActiva) ...[
const SizedBox(height: 12),
Text(
'Categoria: ${widget.categoria}',
style: Theme.of(context).textTheme.bodyLarge
?.copyWith(color: TemaApp.colorNaranja),
),
],
],
)
: Column(
children: [
const Text('Candado', style: TextStyle(fontSize: 48)),
const SizedBox(height: 16),
Text(
l10n.holdToSeeWord,
style: Theme.of(context).textTheme.titleMedium,
textAlign: TextAlign.center,
),
const SizedBox(height: 8),
Text(
l10n.makeSureNoOneLooks,
style: Theme.of(context).textTheme.bodyMedium,
),
],
),
),
const SizedBox(height: 24),
GestureDetector(
onLongPressStart: (_) => setState(() => _manteniendo = true),
onLongPressEnd: (_) => setState(() => _manteniendo = false),
child: Container(
width: double.infinity,
height: 64,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: _manteniendo
? [TemaApp.colorNaranja, TemaApp.colorAcento]
: [TemaApp.colorAcento, TemaApp.colorAcento],
),
borderRadius: BorderRadius.circular(16),
),
child: Center(
child: Text(
_manteniendo ? l10n.showingWord : l10n.holdToSee,
style: const TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
),
),
),
],
),
),
),
);
}
}