feat: foto de perfil seleccionable desde archivo
- file_picker ^4.6.1 — abre galería/archivos (en Android incluye cámara) - BD v3: columna foto_path en usuarios, migración onUpgrade - Usuario modelo: campo fotoPath + copyWith - UsuariosDao: método updateFoto(id, path) - PerfilUsuarioPage: · Avatar muestra foto si hay, iniciales si no · Toque en avatar o ícono cámara → FilePicker → guarda ruta en BD · Ícono editar nombre movido junto al texto del nombre Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
f42467037d
commit
33f0b8aa29
@@ -1,5 +1,7 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import '../theme.dart';
|
||||
import '../models/usuario.dart';
|
||||
import '../db/dao/usuarios_dao.dart';
|
||||
@@ -97,23 +99,30 @@ class _PerfilUsuarioPageState extends State<PerfilUsuarioPage> {
|
||||
ctrl.dispose();
|
||||
if (nuevoNombre == null || nuevoNombre.isEmpty) return;
|
||||
|
||||
final actualizado = Usuario(
|
||||
id: _usuario!.id,
|
||||
final actualizado = _usuario!.copyWith(
|
||||
nombre: nuevoNombre,
|
||||
iniciales: _calcularIniciales(nuevoNombre),
|
||||
nivelAcceso: _usuario!.nivelAcceso,
|
||||
pinHash: _usuario!.pinHash,
|
||||
areas: _usuario!.areas,
|
||||
fechaInicio: _usuario!.fechaInicio,
|
||||
fechaFin: _usuario!.fechaFin,
|
||||
activo: _usuario!.activo,
|
||||
sincronizado: false, // marcar para sincronizar
|
||||
sincronizado: false,
|
||||
);
|
||||
|
||||
await _dao.update(actualizado);
|
||||
if (mounted) setState(() => _usuario = actualizado);
|
||||
}
|
||||
|
||||
// ── Seleccionar foto de perfil ────────────────────────────────────────────
|
||||
Future<void> _seleccionarFoto() async {
|
||||
final result = await FilePicker.platform.pickFiles(
|
||||
type: FileType.image,
|
||||
allowMultiple: false,
|
||||
);
|
||||
if (result == null || result.files.isEmpty) return;
|
||||
final path = result.files.first.path;
|
||||
if (path == null || _usuario == null) return;
|
||||
|
||||
await _dao.updateFoto(_usuario!.id, path);
|
||||
if (mounted) setState(() => _usuario = _usuario!.copyWith(fotoPath: path));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_cargando) {
|
||||
@@ -155,47 +164,68 @@ class _PerfilUsuarioPageState extends State<PerfilUsuarioPage> {
|
||||
borderRadius: BorderRadius.circular(12)),
|
||||
child: Column(children: [
|
||||
Stack(clipBehavior: Clip.none, children: [
|
||||
Container(
|
||||
width: 80, height: 80,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
gradient: const LinearGradient(
|
||||
colors: [AppColors.primary, AppColors.primaryContainer],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
// ── Círculo avatar ───────────────────────────────────────────
|
||||
GestureDetector(
|
||||
onTap: _seleccionarFoto,
|
||||
child: Container(
|
||||
width: 80, height: 80,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
gradient: _usuario?.fotoPath == null
|
||||
? const LinearGradient(
|
||||
colors: [AppColors.primary, AppColors.primaryContainer],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
)
|
||||
: null,
|
||||
boxShadow: [BoxShadow(
|
||||
color: AppColors.primary.withOpacity(0.3),
|
||||
blurRadius: 20, spreadRadius: 2,
|
||||
)],
|
||||
),
|
||||
child: ClipOval(
|
||||
child: _usuario?.fotoPath != null
|
||||
? Image.file(
|
||||
File(_usuario!.fotoPath!),
|
||||
width: 80, height: 80,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (_, __, ___) => _avatarIniciales(iniciales),
|
||||
)
|
||||
: _avatarIniciales(iniciales),
|
||||
),
|
||||
boxShadow: [BoxShadow(
|
||||
color: AppColors.primary.withOpacity(0.3),
|
||||
blurRadius: 20, spreadRadius: 2,
|
||||
)],
|
||||
),
|
||||
child: Center(
|
||||
child: Text(iniciales,
|
||||
style: appHeadline(size: 28, weight: FontWeight.w800,
|
||||
color: AppColors.primaryContainer)),
|
||||
),
|
||||
),
|
||||
// ── Botón cámara ─────────────────────────────────────────────
|
||||
Positioned(
|
||||
bottom: 0, right: 0,
|
||||
child: GestureDetector(
|
||||
onTap: _editarNombre,
|
||||
onTap: _seleccionarFoto,
|
||||
child: Container(
|
||||
width: 24, height: 24,
|
||||
width: 26, height: 26,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceHighest,
|
||||
color: AppColors.primary,
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: AppColors.surfaceHigh, width: 2),
|
||||
),
|
||||
child: const Icon(Icons.edit,
|
||||
size: 13, color: AppColors.primary),
|
||||
child: const Icon(Icons.camera_alt,
|
||||
size: 13, color: AppColors.primaryContainer),
|
||||
),
|
||||
),
|
||||
),
|
||||
]),
|
||||
const SizedBox(height: 16),
|
||||
Text(nombre,
|
||||
style: appHeadline(size: 20, weight: FontWeight.w800)),
|
||||
// ── Nombre con botón editar ──────────────────────────────────
|
||||
Row(mainAxisAlignment: MainAxisAlignment.center, children: [
|
||||
Text(nombre,
|
||||
style: appHeadline(size: 20, weight: FontWeight.w800)),
|
||||
const SizedBox(width: 8),
|
||||
GestureDetector(
|
||||
onTap: _editarNombre,
|
||||
child: const Icon(Icons.edit,
|
||||
size: 15, color: AppColors.primary),
|
||||
),
|
||||
]),
|
||||
const SizedBox(height: 4),
|
||||
Text('Operador de Seguridad', style: appLabel(size: 13)),
|
||||
const SizedBox(height: 12),
|
||||
@@ -211,6 +241,14 @@ class _PerfilUsuarioPageState extends State<PerfilUsuarioPage> {
|
||||
]),
|
||||
);
|
||||
|
||||
Widget _avatarIniciales(String iniciales) => Center(
|
||||
child: Text(iniciales,
|
||||
style: appHeadline(
|
||||
size: 28,
|
||||
weight: FontWeight.w800,
|
||||
color: AppColors.primaryContainer)),
|
||||
);
|
||||
|
||||
// ── Estadísticas ───────────────────────────────────────────────────────────
|
||||
Widget _statsGrid() => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
||||
Reference in New Issue
Block a user