From f41fbc7dd9a8301d522949c6a0350a2bd6f1f550 Mon Sep 17 00:00:00 2001 From: FreeTLab Date: Fri, 24 Apr 2026 21:34:40 +0200 Subject: [PATCH] fix: boton ver palabra del host ahora funciona --- lib/pantallas/pantalla_gestor_host.dart | 197 +++++++++++++++++++++++- 1 file changed, 195 insertions(+), 2 deletions(-) diff --git a/lib/pantallas/pantalla_gestor_host.dart b/lib/pantallas/pantalla_gestor_host.dart index 3783123..282ac98 100644 --- a/lib/pantallas/pantalla_gestor_host.dart +++ b/lib/pantallas/pantalla_gestor_host.dart @@ -7,7 +7,6 @@ import '../modelos/partida.dart'; import '../servicios/servicio_nearby.dart'; import '../tema/tema_app.dart'; - class PantallaGestorHost extends StatefulWidget { final VoidCallback onPartidaFin; @@ -253,6 +252,21 @@ class _PantallaGestorHostState extends State { ), ), 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) Container( padding: const EdgeInsets.all(12), @@ -278,6 +292,31 @@ class _PantallaGestorHostState extends State { ); } + void _mostrarPalabraHost(BuildContext context) { + final estado = context.read(); + final partida = estado.partida; + if (partida == null) return; + + // Buscar el jugador host local + final hostLocal = partida.jugadores.firstWhere( + (j) => j.nombre == context.read().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( BuildContext context, AppLocalizations l10n, @@ -451,7 +490,10 @@ class _PantallaGestorHostState extends State { ), child: Row( children: [ - Text(esHost ? '👑' : '🎭', style: const TextStyle(fontSize: 18)), + Text( + esHost ? 'Host' : 'Cliente', + style: const TextStyle(fontSize: 18), + ), const SizedBox(width: 8), Expanded(child: Text(nombre)), if (listo) @@ -512,3 +554,154 @@ class _PantallaGestorHostState extends State { } } } + +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, + ), + ), + ), + ), + ), + ], + ), + ), + ), + ); + } +}