avatares más grandes y usuario por defecto en partida individual
This commit is contained in:
@@ -37,6 +37,7 @@ class _PantallaCrearPartidaState extends State<PantallaCrearPartida> {
|
||||
int? _tiempoDebate;
|
||||
final List<String> _jugadores = [];
|
||||
final _controladorNombre = TextEditingController();
|
||||
bool _agregandoPerfilPendiente = false;
|
||||
|
||||
final _opcionesTiempo = <int?>[null, 60, 120, 180, 300];
|
||||
|
||||
@@ -44,6 +45,22 @@ class _PantallaCrearPartidaState extends State<PantallaCrearPartida> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
_modoMultimovil = widget.modoInicial;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) _agregarPerfilLocalSiNecesario();
|
||||
});
|
||||
}
|
||||
|
||||
void _agregarPerfilLocalSiNecesario() {
|
||||
if (_modoMultimovil) return;
|
||||
final servicioPerfil = context.read<ServicioPerfilUsuario>();
|
||||
if (!servicioPerfil.cargado) return;
|
||||
final perfil = servicioPerfil.perfil;
|
||||
final nombre =
|
||||
perfil.nombre.trim().isEmpty ? 'Jugador' : perfil.nombre.trim();
|
||||
if (_jugadores.contains(nombre)) return;
|
||||
setState(() {
|
||||
_jugadores.insert(0, nombre);
|
||||
});
|
||||
}
|
||||
|
||||
int get _maxImpostores =>
|
||||
@@ -83,6 +100,10 @@ class _PantallaCrearPartidaState extends State<PantallaCrearPartida> {
|
||||
}
|
||||
|
||||
void _eliminarJugador(int index) {
|
||||
final perfil = context.read<ServicioPerfilUsuario>().perfil;
|
||||
final nombrePerfil =
|
||||
perfil.nombre.trim().isEmpty ? 'Jugador' : perfil.nombre.trim();
|
||||
if (index == 0 && _jugadores[index] == nombrePerfil) return;
|
||||
setState(() {
|
||||
_jugadores.removeAt(index);
|
||||
if (_numImpostores > _maxImpostores && _maxImpostores > 0) {
|
||||
@@ -276,8 +297,22 @@ class _PantallaCrearPartidaState extends State<PantallaCrearPartida> {
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final estado = context.watch<EstadoJuego>();
|
||||
final servicioPerfil = context.watch<ServicioPerfilUsuario>();
|
||||
final categorias = ['todas', ...?estado.banco?.nombresCategorias];
|
||||
final etiquetas = _etiquetasTiempo(l10n);
|
||||
final nombrePerfilActual = servicioPerfil.perfil.nombre.trim().isEmpty
|
||||
? 'Jugador'
|
||||
: servicioPerfil.perfil.nombre.trim();
|
||||
if (!_modoMultimovil &&
|
||||
servicioPerfil.cargado &&
|
||||
!_agregandoPerfilPendiente &&
|
||||
!_jugadores.contains(nombrePerfilActual)) {
|
||||
_agregandoPerfilPendiente = true;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_agregandoPerfilPendiente = false;
|
||||
if (mounted) _agregarPerfilLocalSiNecesario();
|
||||
});
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(l10n.createGame)),
|
||||
@@ -347,6 +382,7 @@ class _PantallaCrearPartidaState extends State<PantallaCrearPartida> {
|
||||
_numImpostores = _maxImpostores;
|
||||
}
|
||||
});
|
||||
_agregarPerfilLocalSiNecesario();
|
||||
},
|
||||
),
|
||||
],
|
||||
@@ -457,22 +493,42 @@ class _PantallaCrearPartidaState extends State<PantallaCrearPartida> {
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
..._jugadores.asMap().entries.map((e) {
|
||||
final perfil = servicioPerfil.perfil;
|
||||
final nombrePerfil = perfil.nombre.trim().isEmpty
|
||||
? 'Jugador'
|
||||
: perfil.nombre.trim();
|
||||
final inicialPerfil = nombrePerfil.isEmpty
|
||||
? '?'
|
||||
: nombrePerfil.substring(0, 1).toUpperCase();
|
||||
final esPerfilLocal =
|
||||
e.key == 0 && e.value == nombrePerfil;
|
||||
return ListTile(
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: TemaApp.colorTarjeta,
|
||||
child: Text(
|
||||
'${e.key + 1}',
|
||||
style: const TextStyle(color: TemaApp.colorTexto),
|
||||
),
|
||||
),
|
||||
leading: esPerfilLocal
|
||||
? AvatarFarolero(
|
||||
texto: inicialPerfil,
|
||||
assetPath: perfil.avatarAsset,
|
||||
size: 54,
|
||||
)
|
||||
: CircleAvatar(
|
||||
backgroundColor: TemaApp.colorTarjeta,
|
||||
child: Text(
|
||||
'${e.key + 1}',
|
||||
style: const TextStyle(color: TemaApp.colorTexto),
|
||||
),
|
||||
),
|
||||
title: Text(e.value),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(
|
||||
Icons.close,
|
||||
color: TemaApp.colorAcento,
|
||||
),
|
||||
onPressed: () => _eliminarJugador(e.key),
|
||||
),
|
||||
subtitle: esPerfilLocal
|
||||
? const Text('Usuario principal del dispositivo')
|
||||
: null,
|
||||
trailing: esPerfilLocal
|
||||
? const Icon(Icons.lock, color: TemaApp.colorDorado)
|
||||
: IconButton(
|
||||
icon: const Icon(
|
||||
Icons.close,
|
||||
color: TemaApp.colorAcento,
|
||||
),
|
||||
onPressed: () => _eliminarJugador(e.key),
|
||||
),
|
||||
dense: true,
|
||||
);
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user