Gestión de usuarios y avatares en la aplicación. Gestión de traducciones de las palabras.
|
After Width: | Height: | Size: 9.4 KiB |
|
After Width: | Height: | Size: 8.6 KiB |
|
After Width: | Height: | Size: 8.7 KiB |
|
After Width: | Height: | Size: 8.4 KiB |
|
After Width: | Height: | Size: 9.1 KiB |
|
After Width: | Height: | Size: 9.4 KiB |
|
After Width: | Height: | Size: 8.6 KiB |
|
After Width: | Height: | Size: 9.2 KiB |
|
After Width: | Height: | Size: 8.4 KiB |
|
After Width: | Height: | Size: 8.7 KiB |
|
After Width: | Height: | Size: 9.2 KiB |
|
After Width: | Height: | Size: 9.3 KiB |
|
After Width: | Height: | Size: 8.6 KiB |
|
After Width: | Height: | Size: 8.4 KiB |
|
After Width: | Height: | Size: 9.2 KiB |
|
After Width: | Height: | Size: 8.9 KiB |
|
After Width: | Height: | Size: 8.8 KiB |
|
After Width: | Height: | Size: 8.8 KiB |
|
After Width: | Height: | Size: 8.3 KiB |
|
After Width: | Height: | Size: 8.8 KiB |
|
After Width: | Height: | Size: 9.2 KiB |
|
After Width: | Height: | Size: 8.7 KiB |
|
After Width: | Height: | Size: 8.5 KiB |
|
After Width: | Height: | Size: 8.5 KiB |
|
After Width: | Height: | Size: 8.9 KiB |
|
After Width: | Height: | Size: 8.5 KiB |
|
After Width: | Height: | Size: 7.9 KiB |
|
After Width: | Height: | Size: 8.8 KiB |
|
After Width: | Height: | Size: 8.3 KiB |
|
After Width: | Height: | Size: 8.2 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 14 KiB |
@@ -4,8 +4,10 @@ import 'package:flutter_localizations/flutter_localizations.dart';
|
|||||||
import 'package:farolero/l10n/generated/app_localizations.dart';
|
import 'package:farolero/l10n/generated/app_localizations.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'estado/estado_juego.dart';
|
import 'estado/estado_juego.dart';
|
||||||
|
import 'servicios/servicio_historial_partidas.dart';
|
||||||
import 'servicios/servicio_idioma.dart';
|
import 'servicios/servicio_idioma.dart';
|
||||||
import 'servicios/servicio_nearby.dart';
|
import 'servicios/servicio_nearby.dart';
|
||||||
|
import 'servicios/servicio_perfil_usuario.dart';
|
||||||
import 'tema/componentes_farolero.dart';
|
import 'tema/componentes_farolero.dart';
|
||||||
import 'tema/tema_app.dart';
|
import 'tema/tema_app.dart';
|
||||||
import 'pantallas/pantalla_principal.dart';
|
import 'pantallas/pantalla_principal.dart';
|
||||||
@@ -36,6 +38,12 @@ class FaroleroApp extends StatelessWidget {
|
|||||||
ChangeNotifierProvider(
|
ChangeNotifierProvider(
|
||||||
create: (_) => ServicioIdioma()..cargar(),
|
create: (_) => ServicioIdioma()..cargar(),
|
||||||
),
|
),
|
||||||
|
ChangeNotifierProvider(
|
||||||
|
create: (_) => ServicioPerfilUsuario()..cargar(),
|
||||||
|
),
|
||||||
|
ChangeNotifierProvider(
|
||||||
|
create: (_) => ServicioHistorialPartidas()..cargar(),
|
||||||
|
),
|
||||||
ChangeNotifierProvider(
|
ChangeNotifierProvider(
|
||||||
create: (_) => ServicioNearby(),
|
create: (_) => ServicioNearby(),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -95,3 +95,48 @@ class BancoPalabras {
|
|||||||
return nombres[clave] ?? clave;
|
return nombres[clave] ?? clave;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class EntradaPalabraTraducida {
|
||||||
|
final String palabra;
|
||||||
|
final Map<String, String> traducciones;
|
||||||
|
|
||||||
|
const EntradaPalabraTraducida({
|
||||||
|
required this.palabra,
|
||||||
|
required this.traducciones,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
class BancoPalabrasTraducidas {
|
||||||
|
final Map<String, List<EntradaPalabraTraducida>> categorias;
|
||||||
|
|
||||||
|
const BancoPalabrasTraducidas(this.categorias);
|
||||||
|
|
||||||
|
static BancoPalabrasTraducidas? _instancia;
|
||||||
|
|
||||||
|
static Future<BancoPalabrasTraducidas> cargar() async {
|
||||||
|
if (_instancia != null) return _instancia!;
|
||||||
|
|
||||||
|
final jsonStr = await rootBundle.loadString('assets/palabras_i18n.json');
|
||||||
|
final data = json.decode(jsonStr) as Map<String, dynamic>;
|
||||||
|
final cats = data['categorias'] as Map<String, dynamic>;
|
||||||
|
final mapa = <String, List<EntradaPalabraTraducida>>{};
|
||||||
|
|
||||||
|
for (final categoria in cats.entries) {
|
||||||
|
final entradas = categoria.value as List<dynamic>;
|
||||||
|
mapa[categoria.key] = entradas.map((entradaRaw) {
|
||||||
|
final entrada = entradaRaw as Map<String, dynamic>;
|
||||||
|
final traduccionesRaw =
|
||||||
|
entrada['traducciones'] as Map<String, dynamic>? ?? {};
|
||||||
|
return EntradaPalabraTraducida(
|
||||||
|
palabra: entrada['es'] as String,
|
||||||
|
traducciones: traduccionesRaw.map(
|
||||||
|
(idioma, valor) => MapEntry(idioma, valor?.toString() ?? ''),
|
||||||
|
)..removeWhere((_, valor) => valor.isEmpty),
|
||||||
|
);
|
||||||
|
}).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
_instancia = BancoPalabrasTraducidas(mapa);
|
||||||
|
return _instancia!;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,14 +2,18 @@
|
|||||||
class Usuario {
|
class Usuario {
|
||||||
final String id;
|
final String id;
|
||||||
final String nombre;
|
final String nombre;
|
||||||
|
final String? nick;
|
||||||
final String? avatar;
|
final String? avatar;
|
||||||
|
final String? foto;
|
||||||
final String? creadoPorClienteId;
|
final String? creadoPorClienteId;
|
||||||
final String? clienteIdSeleccionado;
|
final String? clienteIdSeleccionado;
|
||||||
|
|
||||||
Usuario({
|
Usuario({
|
||||||
required this.id,
|
required this.id,
|
||||||
required this.nombre,
|
required this.nombre,
|
||||||
|
this.nick,
|
||||||
this.avatar,
|
this.avatar,
|
||||||
|
this.foto,
|
||||||
this.creadoPorClienteId,
|
this.creadoPorClienteId,
|
||||||
this.clienteIdSeleccionado,
|
this.clienteIdSeleccionado,
|
||||||
});
|
});
|
||||||
@@ -20,7 +24,9 @@ class Usuario {
|
|||||||
Usuario copiar({
|
Usuario copiar({
|
||||||
String? id,
|
String? id,
|
||||||
String? nombre,
|
String? nombre,
|
||||||
|
String? nick,
|
||||||
String? avatar,
|
String? avatar,
|
||||||
|
String? foto,
|
||||||
String? creadoPorClienteId,
|
String? creadoPorClienteId,
|
||||||
String? clienteIdSeleccionado,
|
String? clienteIdSeleccionado,
|
||||||
bool liberarSeleccion = false,
|
bool liberarSeleccion = false,
|
||||||
@@ -28,7 +34,9 @@ class Usuario {
|
|||||||
return Usuario(
|
return Usuario(
|
||||||
id: id ?? this.id,
|
id: id ?? this.id,
|
||||||
nombre: nombre ?? this.nombre,
|
nombre: nombre ?? this.nombre,
|
||||||
|
nick: nick ?? this.nick,
|
||||||
avatar: avatar ?? this.avatar,
|
avatar: avatar ?? this.avatar,
|
||||||
|
foto: foto ?? this.foto,
|
||||||
creadoPorClienteId: creadoPorClienteId ?? this.creadoPorClienteId,
|
creadoPorClienteId: creadoPorClienteId ?? this.creadoPorClienteId,
|
||||||
clienteIdSeleccionado: liberarSeleccion
|
clienteIdSeleccionado: liberarSeleccion
|
||||||
? null
|
? null
|
||||||
@@ -39,7 +47,9 @@ class Usuario {
|
|||||||
Map<String, dynamic> toJson() => {
|
Map<String, dynamic> toJson() => {
|
||||||
'id': id,
|
'id': id,
|
||||||
'nombre': nombre,
|
'nombre': nombre,
|
||||||
|
if (nick != null) 'nick': nick,
|
||||||
if (avatar != null) 'avatar': avatar,
|
if (avatar != null) 'avatar': avatar,
|
||||||
|
if (foto != null) 'foto': foto,
|
||||||
if (creadoPorClienteId != null) 'creadoPorClienteId': creadoPorClienteId,
|
if (creadoPorClienteId != null) 'creadoPorClienteId': creadoPorClienteId,
|
||||||
if (clienteIdSeleccionado != null)
|
if (clienteIdSeleccionado != null)
|
||||||
'clienteIdSeleccionado': clienteIdSeleccionado,
|
'clienteIdSeleccionado': clienteIdSeleccionado,
|
||||||
@@ -48,7 +58,9 @@ class Usuario {
|
|||||||
factory Usuario.fromJson(Map<String, dynamic> json) => Usuario(
|
factory Usuario.fromJson(Map<String, dynamic> json) => Usuario(
|
||||||
id: json['id'] as String,
|
id: json['id'] as String,
|
||||||
nombre: json['nombre'] as String,
|
nombre: json['nombre'] as String,
|
||||||
|
nick: json['nick'] as String?,
|
||||||
avatar: json['avatar'] as String?,
|
avatar: json['avatar'] as String?,
|
||||||
|
foto: json['foto'] as String?,
|
||||||
creadoPorClienteId: json['creadoPorClienteId'] as String?,
|
creadoPorClienteId: json['creadoPorClienteId'] as String?,
|
||||||
clienteIdSeleccionado: json['clienteIdSeleccionado'] as String?,
|
clienteIdSeleccionado: json['clienteIdSeleccionado'] as String?,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:farolero/l10n/generated/app_localizations.dart';
|
import 'package:farolero/l10n/generated/app_localizations.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import '../servicios/servicio_idioma.dart';
|
import '../servicios/servicio_idioma.dart';
|
||||||
|
import '../servicios/servicio_perfil_usuario.dart';
|
||||||
import '../tema/componentes_farolero.dart';
|
import '../tema/componentes_farolero.dart';
|
||||||
import '../tema/tema_app.dart';
|
import '../tema/tema_app.dart';
|
||||||
|
|
||||||
@@ -20,6 +21,7 @@ class _PantallaAjustesState extends State<PantallaAjustes> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final l10n = AppLocalizations.of(context)!;
|
final l10n = AppLocalizations.of(context)!;
|
||||||
final servicioIdioma = context.watch<ServicioIdioma>();
|
final servicioIdioma = context.watch<ServicioIdioma>();
|
||||||
|
final perfil = context.watch<ServicioPerfilUsuario>().perfil;
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(title: Text(l10n.settingsTitle)),
|
appBar: AppBar(title: Text(l10n.settingsTitle)),
|
||||||
@@ -29,6 +31,21 @@ class _PantallaAjustesState extends State<PantallaAjustes> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
|
Card(
|
||||||
|
child: ListTile(
|
||||||
|
leading: AvatarFarolero(
|
||||||
|
texto: perfil.nombre.substring(0, 1).toUpperCase(),
|
||||||
|
assetPath: perfil.avatarAsset,
|
||||||
|
size: 48,
|
||||||
|
),
|
||||||
|
title: Text(perfil.nombre),
|
||||||
|
subtitle: Text('@${perfil.nick}'),
|
||||||
|
trailing: const Icon(Icons.edit),
|
||||||
|
onTap: () => _editarPerfil(context),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
|
||||||
// Selector de idioma
|
// Selector de idioma
|
||||||
Card(
|
Card(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
@@ -173,6 +190,107 @@ class _PantallaAjustesState extends State<PantallaAjustes> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _editarPerfil(BuildContext context) async {
|
||||||
|
final servicioPerfil = context.read<ServicioPerfilUsuario>();
|
||||||
|
final actual = servicioPerfil.perfil;
|
||||||
|
final nombreController = TextEditingController(text: actual.nombre);
|
||||||
|
final nickController = TextEditingController(text: actual.nick);
|
||||||
|
var avatarSeleccionado = actual.avatarAsset;
|
||||||
|
|
||||||
|
await showDialog<void>(
|
||||||
|
context: context,
|
||||||
|
builder: (ctx) => StatefulBuilder(
|
||||||
|
builder: (ctx, setDialogState) => AlertDialog(
|
||||||
|
title: const Text('Perfil del dispositivo'),
|
||||||
|
content: SizedBox(
|
||||||
|
width: 420,
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
TextField(
|
||||||
|
controller: nombreController,
|
||||||
|
textCapitalization: TextCapitalization.words,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
labelText: 'Nombre',
|
||||||
|
prefixIcon: Icon(Icons.person),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
TextField(
|
||||||
|
controller: nickController,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
labelText: 'Nick',
|
||||||
|
prefixIcon: Icon(Icons.alternate_email),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
GridView.builder(
|
||||||
|
shrinkWrap: true,
|
||||||
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
|
gridDelegate:
|
||||||
|
const SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
|
crossAxisCount: 5,
|
||||||
|
mainAxisSpacing: 8,
|
||||||
|
crossAxisSpacing: 8,
|
||||||
|
),
|
||||||
|
itemCount: ServicioPerfilUsuario.avatares.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final avatar = ServicioPerfilUsuario.avatares[index];
|
||||||
|
final seleccionado = avatar == avatarSeleccionado;
|
||||||
|
return InkWell(
|
||||||
|
borderRadius: BorderRadius.circular(999),
|
||||||
|
onTap: () => setDialogState(
|
||||||
|
() => avatarSeleccionado = avatar,
|
||||||
|
),
|
||||||
|
child: Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
border: Border.all(
|
||||||
|
color: seleccionado
|
||||||
|
? TemaApp.colorNaranja
|
||||||
|
: Colors.transparent,
|
||||||
|
width: 3,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: AvatarFarolero(
|
||||||
|
texto: '',
|
||||||
|
assetPath: avatar,
|
||||||
|
size: 48,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(ctx),
|
||||||
|
child: const Text('Cancelar'),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () async {
|
||||||
|
await servicioPerfil.guardar(
|
||||||
|
nombre: nombreController.text,
|
||||||
|
nick: nickController.text,
|
||||||
|
avatarAsset: avatarSeleccionado,
|
||||||
|
);
|
||||||
|
if (ctx.mounted) Navigator.pop(ctx);
|
||||||
|
},
|
||||||
|
child: const Text('Guardar'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
nombreController.dispose();
|
||||||
|
nickController.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
String _nombreIdiomaDelSistema() {
|
String _nombreIdiomaDelSistema() {
|
||||||
final locale = WidgetsBinding.instance.platformDispatcher.locale;
|
final locale = WidgetsBinding.instance.platformDispatcher.locale;
|
||||||
final codigo = locale.countryCode != null && locale.countryCode!.isNotEmpty
|
final codigo = locale.countryCode != null && locale.countryCode!.isNotEmpty
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import '../modelos/partida.dart';
|
|||||||
import '../modelos/usuario.dart';
|
import '../modelos/usuario.dart';
|
||||||
import '../servicios/servicio_nearby.dart';
|
import '../servicios/servicio_nearby.dart';
|
||||||
import '../servicios/servicio_permisos.dart';
|
import '../servicios/servicio_permisos.dart';
|
||||||
|
import '../servicios/servicio_perfil_usuario.dart';
|
||||||
import '../tema/componentes_farolero.dart';
|
import '../tema/componentes_farolero.dart';
|
||||||
import '../tema/tema_app.dart';
|
import '../tema/tema_app.dart';
|
||||||
import 'pantalla_gestor_host.dart';
|
import 'pantalla_gestor_host.dart';
|
||||||
@@ -131,8 +132,14 @@ class _PantallaCrearPartidaState extends State<PantallaCrearPartida> {
|
|||||||
// 3. Iniciar host en Nearby
|
// 3. Iniciar host en Nearby
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
final nearby = context.read<ServicioNearby>();
|
final nearby = context.read<ServicioNearby>();
|
||||||
|
final perfil = context.read<ServicioPerfilUsuario>().perfil;
|
||||||
final nombreSala = '${nombre.trim()} - Farolero';
|
final nombreSala = '${nombre.trim()} - Farolero';
|
||||||
final ok = await nearby.iniciarHost(nombreSala, nombre.trim());
|
final ok = await nearby.iniciarHost(
|
||||||
|
nombreSala,
|
||||||
|
nombre.trim(),
|
||||||
|
miNick: perfil.nick,
|
||||||
|
miAvatar: perfil.avatarAsset,
|
||||||
|
);
|
||||||
|
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
@@ -279,7 +286,11 @@ class _PantallaCrearPartidaState extends State<PantallaCrearPartida> {
|
|||||||
value: usuario.nombre,
|
value: usuario.nombre,
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Text(usuario.avatar ?? '👤'),
|
AvatarFarolero(
|
||||||
|
texto: usuario.nombre.substring(0, 1),
|
||||||
|
assetPath: usuario.avatar,
|
||||||
|
size: 28,
|
||||||
|
),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
Text(usuario.nombre),
|
Text(usuario.nombre),
|
||||||
],
|
],
|
||||||
@@ -324,6 +335,7 @@ class _PantallaCrearPartidaState extends State<PantallaCrearPartida> {
|
|||||||
final controller = TextEditingController();
|
final controller = TextEditingController();
|
||||||
final l10n = AppLocalizations.of(context)!;
|
final l10n = AppLocalizations.of(context)!;
|
||||||
final nearby = context.read<ServicioNearby>();
|
final nearby = context.read<ServicioNearby>();
|
||||||
|
controller.text = context.read<ServicioPerfilUsuario>().perfil.nombre;
|
||||||
|
|
||||||
final nombre = await showDialog<String>(
|
final nombre = await showDialog<String>(
|
||||||
context: context,
|
context: context,
|
||||||
@@ -356,6 +368,9 @@ class _PantallaCrearPartidaState extends State<PantallaCrearPartida> {
|
|||||||
final nuevoUsuario = Usuario(
|
final nuevoUsuario = Usuario(
|
||||||
id: DateTime.now().millisecondsSinceEpoch.toString(),
|
id: DateTime.now().millisecondsSinceEpoch.toString(),
|
||||||
nombre: nombre.trim(),
|
nombre: nombre.trim(),
|
||||||
|
nick: context.read<ServicioPerfilUsuario>().perfil.nick,
|
||||||
|
avatar: context.read<ServicioPerfilUsuario>().perfil.avatarAsset,
|
||||||
|
foto: context.read<ServicioPerfilUsuario>().perfil.avatarAsset,
|
||||||
);
|
);
|
||||||
nearby.agregarUsuario(nuevoUsuario);
|
nearby.agregarUsuario(nuevoUsuario);
|
||||||
return nombre.trim();
|
return nombre.trim();
|
||||||
@@ -366,6 +381,7 @@ class _PantallaCrearPartidaState extends State<PantallaCrearPartida> {
|
|||||||
/// Método original para pedir nombre (usado cuando pool vacío)
|
/// Método original para pedir nombre (usado cuando pool vacío)
|
||||||
Future<String?> _pedirNombreHost() async {
|
Future<String?> _pedirNombreHost() async {
|
||||||
final controller = TextEditingController();
|
final controller = TextEditingController();
|
||||||
|
controller.text = context.read<ServicioPerfilUsuario>().perfil.nombre;
|
||||||
final l10n = AppLocalizations.of(context)!;
|
final l10n = AppLocalizations.of(context)!;
|
||||||
return showDialog<String>(
|
return showDialog<String>(
|
||||||
context: context,
|
context: context,
|
||||||
|
|||||||
@@ -3,13 +3,21 @@ import 'package:farolero/l10n/generated/app_localizations.dart';
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import '../estado/estado_juego.dart';
|
import '../estado/estado_juego.dart';
|
||||||
import '../modelos/palabra.dart';
|
import '../modelos/palabra.dart';
|
||||||
|
import '../servicios/servicio_historial_partidas.dart';
|
||||||
import '../tema/tema_app.dart';
|
import '../tema/tema_app.dart';
|
||||||
import 'pantalla_principal.dart';
|
import 'pantalla_principal.dart';
|
||||||
import 'pantalla_ver_palabra.dart';
|
import 'pantalla_ver_palabra.dart';
|
||||||
|
|
||||||
class PantallaFinPartida extends StatelessWidget {
|
class PantallaFinPartida extends StatefulWidget {
|
||||||
const PantallaFinPartida({super.key});
|
const PantallaFinPartida({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<PantallaFinPartida> createState() => _PantallaFinPartidaState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _PantallaFinPartidaState extends State<PantallaFinPartida> {
|
||||||
|
bool _guardada = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final l10n = AppLocalizations.of(context)!;
|
final l10n = AppLocalizations.of(context)!;
|
||||||
@@ -20,6 +28,14 @@ class PantallaFinPartida extends StatelessWidget {
|
|||||||
final ganaronJugadores = partida.ganador == 'jugadores';
|
final ganaronJugadores = partida.ganador == 'jugadores';
|
||||||
final impostores =
|
final impostores =
|
||||||
partida.jugadores.where((j) => j.esImpostor).toList();
|
partida.jugadores.where((j) => j.esImpostor).toList();
|
||||||
|
if (!_guardada && partida.ganador != null) {
|
||||||
|
_guardada = true;
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
if (mounted) {
|
||||||
|
context.read<ServicioHistorialPartidas>().guardarPartida(partida);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
import '../servicios/servicio_historial_partidas.dart';
|
||||||
|
import '../tema/componentes_farolero.dart';
|
||||||
|
import '../tema/tema_app.dart';
|
||||||
|
|
||||||
|
class PantallaHistorial extends StatelessWidget {
|
||||||
|
const PantallaHistorial({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final historial = context.watch<ServicioHistorialPartidas>();
|
||||||
|
final partidas = historial.partidas;
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(title: const Text('Historial')),
|
||||||
|
body: FondoFarolero(
|
||||||
|
child: partidas.isEmpty
|
||||||
|
? const Center(child: Text('Todavía no hay partidas guardadas.'))
|
||||||
|
: ListView.builder(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
itemCount: partidas.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final partida = partidas[index];
|
||||||
|
final ganaronJugadores = partida.ganador == 'jugadores';
|
||||||
|
return Card(
|
||||||
|
child: ListTile(
|
||||||
|
leading: CircleAvatar(
|
||||||
|
backgroundColor: ganaronJugadores
|
||||||
|
? TemaApp.colorVerde
|
||||||
|
: TemaApp.colorAcento,
|
||||||
|
child: Icon(
|
||||||
|
ganaronJugadores ? Icons.groups : Icons.theater_comedy,
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
title: Text(
|
||||||
|
ganaronJugadores
|
||||||
|
? 'Ganaron los jugadores'
|
||||||
|
: 'Ganaron los impostores',
|
||||||
|
),
|
||||||
|
subtitle: Text(
|
||||||
|
'${partida.jugadores} jugadores · ${partida.impostores} impostor(es) · ${partida.rondas} ronda(s)\n${partida.palabra} · ${partida.categoria}',
|
||||||
|
),
|
||||||
|
isThreeLine: true,
|
||||||
|
trailing: Text(
|
||||||
|
'${partida.fecha.day.toString().padLeft(2, '0')}/${partida.fecha.month.toString().padLeft(2, '0')}',
|
||||||
|
style: Theme.of(context).textTheme.bodySmall,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:qr_flutter/qr_flutter.dart';
|
import 'package:qr_flutter/qr_flutter.dart';
|
||||||
import 'package:farolero/l10n/generated/app_localizations.dart';
|
import 'package:farolero/l10n/generated/app_localizations.dart';
|
||||||
import '../modelos/usuario.dart';
|
import '../modelos/usuario.dart';
|
||||||
import '../servicios/servicio_nearby.dart';
|
import '../servicios/servicio_nearby.dart';
|
||||||
|
import '../servicios/servicio_perfil_usuario.dart';
|
||||||
import '../tema/componentes_farolero.dart';
|
import '../tema/componentes_farolero.dart';
|
||||||
import '../tema/tema_app.dart';
|
import '../tema/tema_app.dart';
|
||||||
|
|
||||||
@@ -208,7 +209,8 @@ class _PantallaLobbyHostState extends State<PantallaLobbyHost> {
|
|||||||
leading: CircleAvatar(
|
leading: CircleAvatar(
|
||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
child: AvatarFarolero(
|
child: AvatarFarolero(
|
||||||
texto: usuario.avatar ?? (usuario.nombre.isEmpty ? '?' : usuario.nombre[0]),
|
texto: usuario.nombre.isEmpty ? '?' : usuario.nombre[0],
|
||||||
|
assetPath: usuario.avatar,
|
||||||
color: seleccionadoPorMi
|
color: seleccionadoPorMi
|
||||||
? TemaApp.colorVerde
|
? TemaApp.colorVerde
|
||||||
: seleccionadoPorOtro
|
: seleccionadoPorOtro
|
||||||
@@ -297,7 +299,13 @@ class _PantallaLobbyHostState extends State<PantallaLobbyHost> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (nombre != null && nombre.trim().isNotEmpty) {
|
if (nombre != null && nombre.trim().isNotEmpty) {
|
||||||
await nearby.crearUsuarioSala(nombre.trim(), seleccionar: true);
|
final perfil = context.read<ServicioPerfilUsuario>().perfil;
|
||||||
|
await nearby.crearUsuarioSala(
|
||||||
|
nombre.trim(),
|
||||||
|
seleccionar: true,
|
||||||
|
nick: perfil.nick,
|
||||||
|
avatar: perfil.avatarAsset,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:farolero/l10n/generated/app_localizations.dart';
|
import 'package:farolero/l10n/generated/app_localizations.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import '../servicios/servicio_perfil_usuario.dart';
|
||||||
import '../tema/componentes_farolero.dart';
|
import '../tema/componentes_farolero.dart';
|
||||||
import '../tema/tema_app.dart';
|
import '../tema/tema_app.dart';
|
||||||
import 'pantalla_ajustes.dart';
|
import 'pantalla_ajustes.dart';
|
||||||
import 'pantalla_crear_partida.dart';
|
import 'pantalla_crear_partida.dart';
|
||||||
|
import 'pantalla_historial.dart';
|
||||||
import 'pantalla_reglas.dart';
|
import 'pantalla_reglas.dart';
|
||||||
import 'pantalla_unirse.dart';
|
import 'pantalla_unirse.dart';
|
||||||
|
|
||||||
@@ -13,6 +16,7 @@ class PantallaPrincipal extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final l10n = AppLocalizations.of(context)!;
|
final l10n = AppLocalizations.of(context)!;
|
||||||
|
final perfil = context.watch<ServicioPerfilUsuario>().perfil;
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: FondoFarolero(
|
body: FondoFarolero(
|
||||||
@@ -27,18 +31,22 @@ class PantallaPrincipal extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
const AvatarFarolero(texto: 'A', size: 48),
|
AvatarFarolero(
|
||||||
|
texto: perfil.nombre.substring(0, 1).toUpperCase(),
|
||||||
|
assetPath: perfil.avatarAsset,
|
||||||
|
size: 48,
|
||||||
|
),
|
||||||
const SizedBox(width: 10),
|
const SizedBox(width: 10),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
'Alex',
|
perfil.nombre,
|
||||||
style: Theme.of(context).textTheme.titleMedium,
|
style: Theme.of(context).textTheme.titleMedium,
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
'Nivel 12',
|
'@${perfil.nick}',
|
||||||
style: Theme.of(context).textTheme.bodySmall,
|
style: Theme.of(context).textTheme.bodySmall,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 3),
|
const SizedBox(height: 3),
|
||||||
@@ -124,7 +132,14 @@ class PantallaPrincipal extends StatelessWidget {
|
|||||||
child: AccesoFarolero(
|
child: AccesoFarolero(
|
||||||
etiqueta: 'Historial',
|
etiqueta: 'Historial',
|
||||||
icono: Icons.history,
|
icono: Icons.history,
|
||||||
onPressed: () {},
|
onPressed: () {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (_) => const PantallaHistorial(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import '../modelos/inicio_partida_multijugador.dart';
|
|||||||
import '../modelos/usuario.dart';
|
import '../modelos/usuario.dart';
|
||||||
import '../servicios/servicio_nearby.dart';
|
import '../servicios/servicio_nearby.dart';
|
||||||
import '../servicios/servicio_permisos.dart';
|
import '../servicios/servicio_permisos.dart';
|
||||||
|
import '../servicios/servicio_perfil_usuario.dart';
|
||||||
import '../tema/componentes_farolero.dart';
|
import '../tema/componentes_farolero.dart';
|
||||||
import '../tema/tema_app.dart';
|
import '../tema/tema_app.dart';
|
||||||
import 'pantalla_palabra_cliente.dart';
|
import 'pantalla_palabra_cliente.dart';
|
||||||
@@ -46,6 +47,10 @@ class _PantallaUnirseState extends State<PantallaUnirse> {
|
|||||||
super.initState();
|
super.initState();
|
||||||
// Registrar listener ANTES del primer build
|
// Registrar listener ANTES del primer build
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
final perfil = context.read<ServicioPerfilUsuario>().perfil;
|
||||||
|
if (_nombreController.text.isEmpty) {
|
||||||
|
_nombreController.text = perfil.nombre;
|
||||||
|
}
|
||||||
_registrarListenerPartida();
|
_registrarListenerPartida();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -701,6 +706,7 @@ class _PantallaUnirseState extends State<PantallaUnirse> {
|
|||||||
final l10n = AppLocalizations.of(context)!;
|
final l10n = AppLocalizations.of(context)!;
|
||||||
final controller = TextEditingController();
|
final controller = TextEditingController();
|
||||||
final nearby = context.read<ServicioNearby>();
|
final nearby = context.read<ServicioNearby>();
|
||||||
|
controller.text = context.read<ServicioPerfilUsuario>().perfil.nombre;
|
||||||
|
|
||||||
final nombre = await showDialog<String>(
|
final nombre = await showDialog<String>(
|
||||||
context: context,
|
context: context,
|
||||||
@@ -730,7 +736,13 @@ class _PantallaUnirseState extends State<PantallaUnirse> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (nombre != null && nombre.trim().isNotEmpty) {
|
if (nombre != null && nombre.trim().isNotEmpty) {
|
||||||
await nearby.crearUsuarioSala(nombre.trim(), seleccionar: true);
|
final perfil = context.read<ServicioPerfilUsuario>().perfil;
|
||||||
|
await nearby.crearUsuarioSala(
|
||||||
|
nombre.trim(),
|
||||||
|
seleccionar: true,
|
||||||
|
nick: perfil.nick,
|
||||||
|
avatar: perfil.avatarAsset,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,115 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
|
import '../modelos/partida.dart';
|
||||||
|
|
||||||
|
class ResultadoPartidaGuardado {
|
||||||
|
final String id;
|
||||||
|
final DateTime fecha;
|
||||||
|
final bool modoMultimovil;
|
||||||
|
final int jugadores;
|
||||||
|
final int impostores;
|
||||||
|
final int rondas;
|
||||||
|
final String ganador;
|
||||||
|
final String palabra;
|
||||||
|
final String categoria;
|
||||||
|
|
||||||
|
const ResultadoPartidaGuardado({
|
||||||
|
required this.id,
|
||||||
|
required this.fecha,
|
||||||
|
required this.modoMultimovil,
|
||||||
|
required this.jugadores,
|
||||||
|
required this.impostores,
|
||||||
|
required this.rondas,
|
||||||
|
required this.ganador,
|
||||||
|
required this.palabra,
|
||||||
|
required this.categoria,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory ResultadoPartidaGuardado.desdePartida(Partida partida) {
|
||||||
|
return ResultadoPartidaGuardado(
|
||||||
|
id: DateTime.now().microsecondsSinceEpoch.toString(),
|
||||||
|
fecha: DateTime.now(),
|
||||||
|
modoMultimovil: partida.config.modoMultimovil,
|
||||||
|
jugadores: partida.jugadores.length,
|
||||||
|
impostores: partida.impostoresTotales,
|
||||||
|
rondas: partida.rondaActual,
|
||||||
|
ganador: partida.ganador ?? 'sin_resultado',
|
||||||
|
palabra: partida.palabraSecreta,
|
||||||
|
categoria: partida.categoriaReal,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {
|
||||||
|
'id': id,
|
||||||
|
'fecha': fecha.toIso8601String(),
|
||||||
|
'modoMultimovil': modoMultimovil,
|
||||||
|
'jugadores': jugadores,
|
||||||
|
'impostores': impostores,
|
||||||
|
'rondas': rondas,
|
||||||
|
'ganador': ganador,
|
||||||
|
'palabra': palabra,
|
||||||
|
'categoria': categoria,
|
||||||
|
};
|
||||||
|
|
||||||
|
factory ResultadoPartidaGuardado.fromJson(Map<String, dynamic> json) {
|
||||||
|
return ResultadoPartidaGuardado(
|
||||||
|
id: json['id'] as String,
|
||||||
|
fecha: DateTime.parse(json['fecha'] as String),
|
||||||
|
modoMultimovil: json['modoMultimovil'] as bool? ?? false,
|
||||||
|
jugadores: json['jugadores'] as int? ?? 0,
|
||||||
|
impostores: json['impostores'] as int? ?? 0,
|
||||||
|
rondas: json['rondas'] as int? ?? 0,
|
||||||
|
ganador: json['ganador'] as String? ?? 'sin_resultado',
|
||||||
|
palabra: json['palabra'] as String? ?? '',
|
||||||
|
categoria: json['categoria'] as String? ?? '',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ServicioHistorialPartidas extends ChangeNotifier {
|
||||||
|
static const _clave = 'historial.partidas';
|
||||||
|
final List<ResultadoPartidaGuardado> _partidas = [];
|
||||||
|
bool _cargado = false;
|
||||||
|
|
||||||
|
List<ResultadoPartidaGuardado> get partidas => List.unmodifiable(_partidas);
|
||||||
|
bool get cargado => _cargado;
|
||||||
|
|
||||||
|
Future<void> cargar() async {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
final raw = prefs.getString(_clave);
|
||||||
|
_partidas.clear();
|
||||||
|
if (raw != null) {
|
||||||
|
final lista = json.decode(raw) as List<dynamic>;
|
||||||
|
_partidas.addAll(
|
||||||
|
lista.map((e) => ResultadoPartidaGuardado.fromJson(e as Map<String, dynamic>)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_cargado = true;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> guardarPartida(Partida partida) async {
|
||||||
|
if (partida.ganador == null) return;
|
||||||
|
_partidas.insert(0, ResultadoPartidaGuardado.desdePartida(partida));
|
||||||
|
if (_partidas.length > 100) _partidas.removeRange(100, _partidas.length);
|
||||||
|
await _persistir();
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> limpiar() async {
|
||||||
|
_partidas.clear();
|
||||||
|
await _persistir();
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _persistir() async {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
await prefs.setString(
|
||||||
|
_clave,
|
||||||
|
json.encode(_partidas.map((p) => p.toJson()).toList()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -204,7 +204,12 @@ class ServicioNearby extends ChangeNotifier {
|
|||||||
|
|
||||||
// ==================== HOST ====================
|
// ==================== HOST ====================
|
||||||
|
|
||||||
Future<bool> iniciarHost(String nombreSala, String miNombre) async {
|
Future<bool> iniciarHost(
|
||||||
|
String nombreSala,
|
||||||
|
String miNombre, {
|
||||||
|
String? miNick,
|
||||||
|
String? miAvatar,
|
||||||
|
}) async {
|
||||||
_nombreSala = nombreSala;
|
_nombreSala = nombreSala;
|
||||||
_miNombre = miNombre;
|
_miNombre = miNombre;
|
||||||
_roomId = DateTime.now().microsecondsSinceEpoch.toString();
|
_roomId = DateTime.now().microsecondsSinceEpoch.toString();
|
||||||
@@ -222,6 +227,9 @@ class ServicioNearby extends ChangeNotifier {
|
|||||||
final usuarioHost = Usuario(
|
final usuarioHost = Usuario(
|
||||||
id: 'u-${_roomId!}-host',
|
id: 'u-${_roomId!}-host',
|
||||||
nombre: miNombre,
|
nombre: miNombre,
|
||||||
|
nick: miNick,
|
||||||
|
avatar: miAvatar,
|
||||||
|
foto: miAvatar,
|
||||||
creadoPorClienteId: _hostClientId,
|
creadoPorClienteId: _hostClientId,
|
||||||
clienteIdSeleccionado: _hostClientId,
|
clienteIdSeleccionado: _hostClientId,
|
||||||
);
|
);
|
||||||
@@ -654,13 +662,21 @@ class ServicioNearby extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> crearUsuarioSala(String nombre, {bool seleccionar = true}) async {
|
Future<void> crearUsuarioSala(
|
||||||
|
String nombre, {
|
||||||
|
bool seleccionar = true,
|
||||||
|
String? nick,
|
||||||
|
String? avatar,
|
||||||
|
}) async {
|
||||||
final nombreLimpio = nombre.trim();
|
final nombreLimpio = nombre.trim();
|
||||||
if (nombreLimpio.isEmpty) return;
|
if (nombreLimpio.isEmpty) return;
|
||||||
final clientId = _miClientId;
|
final clientId = _miClientId;
|
||||||
final usuario = Usuario(
|
final usuario = Usuario(
|
||||||
id: 'u-${DateTime.now().microsecondsSinceEpoch}',
|
id: 'u-${DateTime.now().microsecondsSinceEpoch}',
|
||||||
nombre: nombreLimpio,
|
nombre: nombreLimpio,
|
||||||
|
nick: nick,
|
||||||
|
avatar: avatar,
|
||||||
|
foto: avatar,
|
||||||
creadoPorClienteId: clientId,
|
creadoPorClienteId: clientId,
|
||||||
);
|
);
|
||||||
if (_esHost && _estadoSala != null && clientId != null) {
|
if (_esHost && _estadoSala != null && clientId != null) {
|
||||||
|
|||||||
@@ -0,0 +1,104 @@
|
|||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
|
class PerfilUsuario {
|
||||||
|
final String nombre;
|
||||||
|
final String nick;
|
||||||
|
final String avatarAsset;
|
||||||
|
|
||||||
|
const PerfilUsuario({
|
||||||
|
required this.nombre,
|
||||||
|
required this.nick,
|
||||||
|
required this.avatarAsset,
|
||||||
|
});
|
||||||
|
|
||||||
|
PerfilUsuario copiar({String? nombre, String? nick, String? avatarAsset}) {
|
||||||
|
return PerfilUsuario(
|
||||||
|
nombre: nombre ?? this.nombre,
|
||||||
|
nick: nick ?? this.nick,
|
||||||
|
avatarAsset: avatarAsset ?? this.avatarAsset,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ServicioPerfilUsuario extends ChangeNotifier {
|
||||||
|
static const _claveNombre = 'perfil.nombre';
|
||||||
|
static const _claveNick = 'perfil.nick';
|
||||||
|
static const _claveAvatar = 'perfil.avatar';
|
||||||
|
|
||||||
|
static const avatares = [
|
||||||
|
'assets/avatars/avatar_01.png',
|
||||||
|
'assets/avatars/avatar_02.png',
|
||||||
|
'assets/avatars/avatar_03.png',
|
||||||
|
'assets/avatars/avatar_04.png',
|
||||||
|
'assets/avatars/avatar_05.png',
|
||||||
|
'assets/avatars/avatar_06.png',
|
||||||
|
'assets/avatars/avatar_07.png',
|
||||||
|
'assets/avatars/avatar_08.png',
|
||||||
|
'assets/avatars/avatar_09.png',
|
||||||
|
'assets/avatars/avatar_10.png',
|
||||||
|
'assets/avatars/avatar_11.png',
|
||||||
|
'assets/avatars/avatar_12.png',
|
||||||
|
'assets/avatars/avatar_13.png',
|
||||||
|
'assets/avatars/avatar_14.png',
|
||||||
|
'assets/avatars/avatar_15.png',
|
||||||
|
'assets/avatars/avatar_16.png',
|
||||||
|
'assets/avatars/avatar_17.png',
|
||||||
|
'assets/avatars/avatar_18.png',
|
||||||
|
'assets/avatars/avatar_19.png',
|
||||||
|
'assets/avatars/avatar_20.png',
|
||||||
|
'assets/avatars/avatar_21.png',
|
||||||
|
'assets/avatars/avatar_22.png',
|
||||||
|
'assets/avatars/avatar_23.png',
|
||||||
|
'assets/avatars/avatar_24.png',
|
||||||
|
'assets/avatars/avatar_25.png',
|
||||||
|
'assets/avatars/avatar_26.png',
|
||||||
|
'assets/avatars/avatar_27.png',
|
||||||
|
'assets/avatars/avatar_28.png',
|
||||||
|
'assets/avatars/avatar_29.png',
|
||||||
|
'assets/avatars/avatar_30.png',
|
||||||
|
];
|
||||||
|
|
||||||
|
PerfilUsuario _perfil = const PerfilUsuario(
|
||||||
|
nombre: 'Jugador',
|
||||||
|
nick: 'farolero',
|
||||||
|
avatarAsset: 'assets/avatars/avatar_01.png',
|
||||||
|
);
|
||||||
|
bool _cargado = false;
|
||||||
|
|
||||||
|
PerfilUsuario get perfil => _perfil;
|
||||||
|
bool get cargado => _cargado;
|
||||||
|
|
||||||
|
Future<void> cargar() async {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
_perfil = PerfilUsuario(
|
||||||
|
nombre: prefs.getString(_claveNombre) ?? _perfil.nombre,
|
||||||
|
nick: prefs.getString(_claveNick) ?? _perfil.nick,
|
||||||
|
avatarAsset: prefs.getString(_claveAvatar) ?? _perfil.avatarAsset,
|
||||||
|
);
|
||||||
|
_cargado = true;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> guardar({
|
||||||
|
required String nombre,
|
||||||
|
required String nick,
|
||||||
|
required String avatarAsset,
|
||||||
|
}) async {
|
||||||
|
final nombreLimpio = nombre.trim().isEmpty ? 'Jugador' : nombre.trim();
|
||||||
|
final nickLimpio = nick.trim().isEmpty ? 'farolero' : nick.trim();
|
||||||
|
final avatarSeguro = avatares.contains(avatarAsset)
|
||||||
|
? avatarAsset
|
||||||
|
: avatares.first;
|
||||||
|
_perfil = PerfilUsuario(
|
||||||
|
nombre: nombreLimpio,
|
||||||
|
nick: nickLimpio,
|
||||||
|
avatarAsset: avatarSeguro,
|
||||||
|
);
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
await prefs.setString(_claveNombre, _perfil.nombre);
|
||||||
|
await prefs.setString(_claveNick, _perfil.nick);
|
||||||
|
await prefs.setString(_claveAvatar, _perfil.avatarAsset);
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -269,12 +269,14 @@ class TarjetaPalabraFarolero extends StatelessWidget {
|
|||||||
|
|
||||||
class AvatarFarolero extends StatelessWidget {
|
class AvatarFarolero extends StatelessWidget {
|
||||||
final String texto;
|
final String texto;
|
||||||
|
final String? assetPath;
|
||||||
final Color color;
|
final Color color;
|
||||||
final double size;
|
final double size;
|
||||||
|
|
||||||
const AvatarFarolero({
|
const AvatarFarolero({
|
||||||
super.key,
|
super.key,
|
||||||
required this.texto,
|
required this.texto,
|
||||||
|
this.assetPath,
|
||||||
this.color = TemaApp.colorNaranja,
|
this.color = TemaApp.colorNaranja,
|
||||||
this.size = 40,
|
this.size = 40,
|
||||||
});
|
});
|
||||||
@@ -292,13 +294,22 @@ class AvatarFarolero extends StatelessWidget {
|
|||||||
border: Border.all(color: TemaApp.colorDorado, width: 2),
|
border: Border.all(color: TemaApp.colorDorado, width: 2),
|
||||||
),
|
),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Text(
|
child: assetPath == null
|
||||||
|
? Text(
|
||||||
texto,
|
texto,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: TemaApp.colorTexto,
|
color: TemaApp.colorTexto,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
fontSize: size * 0.36,
|
fontSize: size * 0.36,
|
||||||
),
|
),
|
||||||
|
)
|
||||||
|
: ClipOval(
|
||||||
|
child: Image.asset(
|
||||||
|
assetPath!,
|
||||||
|
width: size,
|
||||||
|
height: size,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -30,5 +30,7 @@ flutter:
|
|||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
assets:
|
assets:
|
||||||
- assets/palabras.json
|
- assets/palabras.json
|
||||||
|
- assets/palabras_i18n.json
|
||||||
- assets/palabras_en.json
|
- assets/palabras_en.json
|
||||||
- assets/palabras_fr.json
|
- assets/palabras_fr.json
|
||||||
|
- assets/avatars/
|
||||||
|
|||||||