Gamificación
This commit is contained in:
@@ -3,8 +3,11 @@ import 'package:farolero/l10n/generated/app_localizations.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../estado/estado_juego.dart';
|
||||
import '../modelos/palabra.dart';
|
||||
import '../modelos/gamificacion_usuario.dart';
|
||||
import '../servicios/servicio_historial_partidas.dart';
|
||||
import '../servicios/servicio_nearby.dart';
|
||||
import '../servicios/servicio_perfil_usuario.dart';
|
||||
import '../tema/componentes_farolero.dart';
|
||||
import '../tema/tema_app.dart';
|
||||
import 'pantalla_principal.dart';
|
||||
import 'pantalla_ver_palabra.dart';
|
||||
@@ -18,6 +21,7 @@ class PantallaFinPartida extends StatefulWidget {
|
||||
|
||||
class _PantallaFinPartidaState extends State<PantallaFinPartida> {
|
||||
bool _guardada = false;
|
||||
ProgresoGamificacionUsuario? _progreso;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -31,9 +35,15 @@ class _PantallaFinPartidaState extends State<PantallaFinPartida> {
|
||||
partida.jugadores.where((j) => j.esImpostor).toList();
|
||||
if (!_guardada && partida.ganador != null) {
|
||||
_guardada = true;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
if (mounted) {
|
||||
context.read<ServicioHistorialPartidas>().guardarPartida(partida);
|
||||
final historial = context.read<ServicioHistorialPartidas>();
|
||||
final perfil = context.read<ServicioPerfilUsuario>();
|
||||
await historial.guardarPartida(partida);
|
||||
final progreso = await perfil.registrarPartidaCompletada(
|
||||
victoria: ganaronJugadores,
|
||||
);
|
||||
if (mounted) setState(() => _progreso = progreso);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -91,6 +101,10 @@ class _PantallaFinPartidaState extends State<PantallaFinPartida> {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
if (_progreso != null) ...[
|
||||
_TarjetaProgresoGamificacion(progreso: _progreso!),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
|
||||
// Palabra secreta
|
||||
Card(
|
||||
@@ -260,3 +274,59 @@ class _PantallaFinPartidaState extends State<PantallaFinPartida> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _TarjetaProgresoGamificacion extends StatelessWidget {
|
||||
final ProgresoGamificacionUsuario progreso;
|
||||
|
||||
const _TarjetaProgresoGamificacion({required this.progreso});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final nuevas = progreso.nuevasMedallas;
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Tu progreso', style: Theme.of(context).textTheme.titleMedium),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
const Text('🔥', style: TextStyle(fontSize: 24)),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
child: LinearProgressIndicator(
|
||||
value: progreso.despues.fuego / 100,
|
||||
minHeight: 8,
|
||||
color: TemaApp.colorNaranja,
|
||||
backgroundColor: Colors.black.withValues(alpha: 0.35),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Text('${progreso.despues.fuego}%'),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
progreso.incrementoFuego >= 0
|
||||
? '+${progreso.incrementoFuego}% de fuego'
|
||||
: '${progreso.incrementoFuego}% de fuego',
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
if (nuevas.isNotEmpty) ...[
|
||||
const SizedBox(height: 12),
|
||||
Text('Nuevas medallas',
|
||||
style: Theme.of(context).textTheme.bodyMedium),
|
||||
const SizedBox(height: 6),
|
||||
MedallasCompactasFarolero(ids: nuevas, max: nuevas.length),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user