This commit is contained in:
2026-03-22 16:16:08 +00:00
parent be103c66b0
commit 9cf7915d12
6 changed files with 303 additions and 163 deletions

View File

@@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:image_cropper/image_cropper.dart';
import 'package:shimmer/shimmer.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:cached_network_image/cached_network_image.dart'; // 👇 MAGIA DO CACHE AQUI
import 'package:supabase_flutter/supabase_flutter.dart';
import 'package:playmaker/classe/theme.dart';
import '../models/team_model.dart';
@@ -11,7 +11,7 @@ import '../models/person_model.dart';
import '../utils/size_extension.dart';
// ==========================================
// 1. CABEÇALHO (AGORA COM CACHE DE IMAGEM)
// 1. CABEÇALHO (AGORA COM CACHE DE IMAGEM INSTANTÂNEO)
// ==========================================
class StatsHeader extends StatelessWidget {
final Team team;
@@ -51,15 +51,27 @@ class StatsHeader extends StatelessWidget {
child: Stack(
alignment: Alignment.center,
children: [
CircleAvatar(
radius: 28 * context.sf,
backgroundColor: Colors.white24,
backgroundImage: (currentImageUrl != null && currentImageUrl!.isNotEmpty && currentImageUrl!.startsWith('http'))
? CachedNetworkImageProvider(currentImageUrl!)
: null,
child: (currentImageUrl == null || currentImageUrl!.isEmpty || !currentImageUrl!.startsWith('http'))
? Text((currentImageUrl != null && currentImageUrl!.isNotEmpty) ? currentImageUrl! : "🛡️", style: TextStyle(fontSize: 24 * context.sf))
: null,
// 👇 AVATAR DA EQUIPA SEM LAG 👇
ClipOval(
child: Container(
width: 56 * context.sf,
height: 56 * context.sf,
color: Colors.white24,
child: (currentImageUrl != null && currentImageUrl!.isNotEmpty && currentImageUrl!.startsWith('http'))
? CachedNetworkImage(
imageUrl: currentImageUrl!,
fit: BoxFit.cover,
fadeInDuration: Duration.zero, // Corta o atraso
placeholder: (context, url) => Center(child: Text("🛡️", style: TextStyle(fontSize: 24 * context.sf))),
errorWidget: (context, url, error) => Center(child: Text("🛡️", style: TextStyle(fontSize: 24 * context.sf))),
)
: Center(
child: Text(
(currentImageUrl != null && currentImageUrl!.isNotEmpty) ? currentImageUrl! : "🛡️",
style: TextStyle(fontSize: 24 * context.sf)
),
),
),
),
Positioned(
bottom: 0, right: 0,
@@ -144,7 +156,7 @@ class StatsSectionTitle extends StatelessWidget {
}
}
// --- CARD DA PESSOA (FOTO + NÚMERO + NOME E CACHE) ---
// --- CARD DA PESSOA (FOTO SEM LAG) ---
class PersonCard extends StatelessWidget {
final Person person;
final bool isCoach;
@@ -158,6 +170,7 @@ class PersonCard extends StatelessWidget {
final Color defaultBg = Theme.of(context).brightness == Brightness.dark ? const Color(0xFF1E1E1E) : Colors.white;
final Color coachBg = Theme.of(context).brightness == Brightness.dark ? AppTheme.warningAmber.withOpacity(0.1) : const Color(0xFFFFF9C4);
final String? pImage = person.imageUrl;
final Color iconColor = isCoach ? Colors.white : AppTheme.primaryRed;
return Card(
margin: EdgeInsets.only(top: 12 * context.sf),
@@ -168,11 +181,22 @@ class PersonCard extends StatelessWidget {
padding: EdgeInsets.symmetric(horizontal: 16 * context.sf, vertical: 12 * context.sf),
child: Row(
children: [
CircleAvatar(
radius: 22 * context.sf,
backgroundColor: isCoach ? AppTheme.warningAmber : AppTheme.primaryRed.withOpacity(0.1),
backgroundImage: (pImage != null && pImage.isNotEmpty) ? CachedNetworkImageProvider(pImage) : null,
child: (pImage == null || pImage.isEmpty) ? Icon(Icons.person, color: isCoach ? Colors.white : AppTheme.primaryRed, size: 24 * context.sf) : null,
// 👇 FOTO DO JOGADOR/TREINADOR INSTANTÂNEA 👇
ClipOval(
child: Container(
width: 44 * context.sf,
height: 44 * context.sf,
color: isCoach ? AppTheme.warningAmber : AppTheme.primaryRed.withOpacity(0.1),
child: (pImage != null && pImage.isNotEmpty)
? CachedNetworkImage(
imageUrl: pImage,
fit: BoxFit.cover,
fadeInDuration: Duration.zero,
placeholder: (context, url) => Icon(Icons.person, color: iconColor, size: 24 * context.sf),
errorWidget: (context, url, error) => Icon(Icons.person, color: iconColor, size: 24 * context.sf),
)
: Icon(Icons.person, color: iconColor, size: 24 * context.sf),
),
),
SizedBox(width: 12 * context.sf),
Expanded(
@@ -385,12 +409,9 @@ void _confirmDelete(BuildContext context, Person person) {
TextButton(onPressed: () => Navigator.pop(ctx), child: const Text("Cancelar", style: TextStyle(color: Colors.grey))),
TextButton(
onPressed: () {
// ⚡ FECHA LOGO O POP-UP!
Navigator.pop(ctx);
// Mostra um aviso rápido para o utilizador saber que a app está a trabalhar
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text("A remover ${person.name}..."), duration: const Duration(seconds: 1)));
// APAGA NO FUNDO
_controller.deletePerson(person).catchError((e) {
if (context.mounted) ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text("Erro: $e"), backgroundColor: AppTheme.primaryRed));
});
@@ -480,7 +501,6 @@ class StatsController {
bool isPickerActive = false;
String? currentImageUrl = isEdit ? person.imageUrl : null;
// 👇 VARIÁVEIS PARA O TEXTO PEQUENO VERMELHO (ESTILO LOGIN) 👇
String? nameError;
String? numError;
@@ -512,15 +532,24 @@ class StatsController {
child: Stack(
alignment: Alignment.center,
children: [
CircleAvatar(
radius: 40 * context.sf,
backgroundColor: Theme.of(context).colorScheme.onSurface.withOpacity(0.05),
backgroundImage: selectedImage != null
? FileImage(selectedImage!)
: (currentImageUrl != null && currentImageUrl!.isNotEmpty ? CachedNetworkImageProvider(currentImageUrl!) : null) as ImageProvider?,
child: (selectedImage == null && (currentImageUrl == null || currentImageUrl!.isEmpty))
? Icon(Icons.add_a_photo, size: 30 * context.sf, color: Colors.grey)
: null,
// 👇 PREVIEW DA FOTO NO POPUP SEM LAG 👇
ClipOval(
child: Container(
width: 80 * context.sf,
height: 80 * context.sf,
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.05),
child: selectedImage != null
? Image.file(selectedImage!, fit: BoxFit.cover)
: (currentImageUrl != null && currentImageUrl!.isNotEmpty)
? CachedNetworkImage(
imageUrl: currentImageUrl!,
fit: BoxFit.cover,
fadeInDuration: Duration.zero,
placeholder: (context, url) => Icon(Icons.add_a_photo, size: 30 * context.sf, color: Colors.grey),
errorWidget: (context, url, error) => Icon(Icons.add_a_photo, size: 30 * context.sf, color: Colors.grey),
)
: Icon(Icons.add_a_photo, size: 30 * context.sf, color: Colors.grey),
),
),
Positioned(
bottom: 0, right: 0,
@@ -540,7 +569,7 @@ class StatsController {
style: TextStyle(color: Theme.of(context).colorScheme.onSurface),
decoration: InputDecoration(
labelText: "Nome Completo",
errorText: nameError, // 👇 ERRO PEQUENO AQUI
errorText: nameError,
),
textCapitalization: TextCapitalization.words,
),
@@ -560,7 +589,7 @@ class StatsController {
style: TextStyle(color: Theme.of(context).colorScheme.onSurface),
decoration: InputDecoration(
labelText: "Número da Camisola",
errorText: numError, // 👇 ERRO PEQUENO AQUI
errorText: numError,
),
keyboardType: TextInputType.number,
),
@@ -574,7 +603,6 @@ class StatsController {
style: ElevatedButton.styleFrom(backgroundColor: AppTheme.successGreen, foregroundColor: Colors.white, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8 * context.sf))),
onPressed: isUploading ? null : () async {
// Limpa os erros antes de tentar de novo
setState(() {
nameError = null;
numError = null;
@@ -621,7 +649,6 @@ class StatsController {
}
if (ctx.mounted) Navigator.pop(ctx);
} catch (e) {
// 👇 AGORA OS ERROS VÃO DIRETOS PARA OS CAMPOS (ESTILO LOGIN) 👇
setState(() {
isUploading = false;
if (e is PostgrestException && e.code == '23505') {