eliminar e tentativa de partilhar

This commit is contained in:
2026-04-04 01:28:47 +01:00
parent 1b08ed7d07
commit 2544e52636
5 changed files with 169 additions and 56 deletions

View File

@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:playmaker/pages/PlacarPage.dart';
import 'package:playmaker/classe/theme.dart';
import 'package:cached_network_image/cached_network_image.dart'; // 👇 A MAGIA DO CACHE AQUI
import 'package:cached_network_image/cached_network_image.dart';
import '../controllers/team_controller.dart';
import '../controllers/game_controller.dart';
import '../models/game_model.dart';
@@ -12,16 +12,17 @@ class GameResultCard extends StatelessWidget {
final String gameId, myTeam, opponentTeam, myScore, opponentScore, status, season;
final String? myTeamLogo, opponentTeamLogo;
final double sf;
final VoidCallback onDelete;
const GameResultCard({
super.key, required this.gameId, required this.myTeam, required this.opponentTeam,
required this.myScore, required this.opponentScore, required this.status, required this.season,
this.myTeamLogo, this.opponentTeamLogo, required this.sf,
this.myTeamLogo, this.opponentTeamLogo, required this.sf, required this.onDelete,
});
@override
Widget build(BuildContext context) {
final bgColor = Theme.of(context).cardTheme.color;
final bgColor = Theme.of(context).cardTheme.color ?? Theme.of(context).colorScheme.surface;
final textColor = Theme.of(context).colorScheme.onSurface;
return Container(
@@ -33,20 +34,57 @@ class GameResultCard extends StatelessWidget {
boxShadow: [BoxShadow(color: Colors.black12, blurRadius: 10 * sf)],
border: Border.all(color: Colors.grey.withOpacity(0.1)),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
child: Stack(
children: [
Expanded(child: _buildTeamInfo(myTeam, AppTheme.primaryRed, myTeamLogo, sf, textColor)),
_buildScoreCenter(context, gameId, sf, textColor),
Expanded(child: _buildTeamInfo(opponentTeam, Colors.grey.shade600, opponentTeamLogo, sf, textColor)),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(child: _buildTeamInfo(myTeam, AppTheme.primaryRed, myTeamLogo, sf, textColor)),
_buildScoreCenter(context, gameId, sf, textColor),
Expanded(child: _buildTeamInfo(opponentTeam, Colors.grey.shade600, opponentTeamLogo, sf, textColor)),
],
),
Positioned(
top: -10 * sf,
right: -10 * sf,
child: IconButton(
icon: Icon(Icons.delete_outline, color: Colors.grey.shade400, size: 22 * sf),
splashRadius: 20 * sf,
onPressed: () => _showDeleteConfirmation(context),
),
),
],
),
);
}
// 👇 AVATAR OTIMIZADO COM CACHE 👇
void _showDeleteConfirmation(BuildContext context) {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
backgroundColor: Theme.of(context).colorScheme.surface,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15 * sf)),
title: Text('Eliminar Jogo', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16 * sf, color: Theme.of(context).colorScheme.onSurface)),
content: Text('Tem a certeza que deseja eliminar este jogo? Esta ação apagará todas as estatísticas associadas e não pode ser desfeita.', style: TextStyle(fontSize: 14 * sf, color: Theme.of(context).colorScheme.onSurface)),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
child: Text('CANCELAR', style: TextStyle(color: Colors.grey, fontSize: 14 * sf))
),
TextButton(
onPressed: () {
Navigator.pop(ctx);
onDelete();
},
child: Text('ELIMINAR', style: TextStyle(color: AppTheme.primaryRed, fontWeight: FontWeight.bold, fontSize: 14 * sf))
),
],
)
);
}
Widget _buildTeamInfo(String name, Color color, String? logoUrl, double sf, Color textColor) {
final double avatarSize = 48 * sf; // 2 * radius (24)
final double avatarSize = 48 * sf;
return Column(
children: [
@@ -54,18 +92,14 @@ class GameResultCard extends StatelessWidget {
child: Container(
width: avatarSize,
height: avatarSize,
color: color.withOpacity(0.1), // Fundo suave para não ser agressivo
color: color.withOpacity(0.1),
child: (logoUrl != null && logoUrl.isNotEmpty)
? CachedNetworkImage(
imageUrl: logoUrl,
fit: BoxFit.cover,
fadeInDuration: Duration.zero, // Fica instantâneo
placeholder: (context, url) => Center(
child: Icon(Icons.shield, color: color, size: 24 * sf)
),
errorWidget: (context, url, error) => Center(
child: Icon(Icons.shield, color: color, size: 24 * sf)
),
fadeInDuration: Duration.zero,
placeholder: (context, url) => Center(child: Icon(Icons.shield, color: color, size: 24 * sf)),
errorWidget: (context, url, error) => Center(child: Icon(Icons.shield, color: color, size: 24 * sf)),
)
: Center(child: Icon(Icons.shield, color: color, size: 24 * sf)),
),
@@ -179,7 +213,6 @@ class _CreateGameDialogManualState extends State<CreateGameDialogManual> {
);
}
// 👇 PESQUISA COM CACHE 👇
Widget _buildSearch(BuildContext context, String label, TextEditingController controller) {
return StreamBuilder<List<Map<String, dynamic>>>(
stream: widget.teamController.teamsStream,
@@ -304,9 +337,33 @@ class _GamePageState extends State<GamePage> {
if (team['name'] == game.opponentTeam) oppLogo = team['image_url'];
}
return GameResultCard(
gameId: game.id, myTeam: game.myTeam, opponentTeam: game.opponentTeam, myScore: game.myScore,
opponentScore: game.opponentScore, status: game.status, season: game.season, myTeamLogo: myLogo, opponentTeamLogo: oppLogo,
gameId: game.id,
myTeam: game.myTeam,
opponentTeam: game.opponentTeam,
myScore: game.myScore,
opponentScore: game.opponentScore,
status: game.status,
season: game.season,
myTeamLogo: myLogo,
opponentTeamLogo: oppLogo,
sf: context.sf,
onDelete: () async {
bool success = await gameController.deleteGame(game.id);
if (context.mounted) {
if (success) {
// 👇 ISTO FORÇA A LISTA A ATUALIZAR IMEDIATAMENTE 👇
setState(() {});
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Jogo eliminado com sucesso!'), backgroundColor: Colors.green)
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Erro ao eliminar o jogo.'), backgroundColor: Colors.red)
);
}
}
},
);
},
);