171 lines
5.6 KiB
Dart
171 lines
5.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../models/team_model.dart';
|
|
import '../controllers/team_controllers.dart';
|
|
|
|
class TeamCard extends StatelessWidget {
|
|
final Team team;
|
|
final TeamController controller; // Recebe o controlador por parâmetro
|
|
|
|
const TeamCard({
|
|
super.key,
|
|
required this.team,
|
|
required this.controller,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Card(
|
|
elevation: 3,
|
|
margin: const EdgeInsets.only(bottom: 12),
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
|
|
child: ListTile(
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
|
|
// 1. LEADING (Lado Esquerdo): Logótipo ou Emoji
|
|
leading: CircleAvatar(
|
|
backgroundColor: Colors.grey[200],
|
|
backgroundImage: (team.imageUrl.startsWith('http'))
|
|
? NetworkImage(team.imageUrl)
|
|
: null,
|
|
child: (!team.imageUrl.startsWith('http'))
|
|
? Text(
|
|
team.imageUrl.isEmpty ? "🏀" : team.imageUrl,
|
|
style: const TextStyle(fontSize: 20),
|
|
)
|
|
: null,
|
|
),
|
|
|
|
// 2. TÍTULO E SUBTÍTULO (Centro)
|
|
title: Text(
|
|
team.name,
|
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
),
|
|
subtitle: Text("Temporada: ${team.season}"),
|
|
|
|
// 3. TRAILING (Lado Direito): Botões de Status e Eliminar
|
|
trailing: SizedBox(
|
|
width: 90, // Espaço fixo para os dois ícones não quebrarem a linha
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
// Botão Status
|
|
IconButton(
|
|
padding: EdgeInsets.zero,
|
|
constraints: const BoxConstraints(),
|
|
icon: const Icon(Icons.bar_chart, color: Colors.blue),
|
|
onPressed: () {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text("A abrir status de ${team.name}...")),
|
|
);
|
|
},
|
|
),
|
|
const SizedBox(width: 12),
|
|
// Botão Eliminar
|
|
IconButton(
|
|
padding: EdgeInsets.zero,
|
|
constraints: const BoxConstraints(),
|
|
icon: const Icon(Icons.delete_outline, color: Color(0xFFE74C3C)),
|
|
onPressed: () => _confirmDelete(context),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
void _confirmDelete(BuildContext context) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: const Text('Eliminar Equipa?'),
|
|
content: Text('Tens a certeza que queres eliminar "${team.name}"? Esta ação não pode ser desfeita.'),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text('Cancelar'),
|
|
),
|
|
TextButton(
|
|
onPressed: () {
|
|
controller.deleteTeam(team.id);
|
|
Navigator.pop(context);
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text("Equipa eliminada com sucesso")),
|
|
);
|
|
},
|
|
child: const Text('Eliminar', style: TextStyle(color: Colors.red)),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
// --- WIDGET DO POPUP (CREATE TEAM DIALOG) ---
|
|
class CreateTeamDialog extends StatefulWidget {
|
|
final Function(String name, String season, String imageUrl) onConfirm;
|
|
|
|
const CreateTeamDialog({super.key, required this.onConfirm});
|
|
|
|
@override
|
|
State<CreateTeamDialog> createState() => _CreateTeamDialogState();
|
|
}
|
|
|
|
class _CreateTeamDialogState extends State<CreateTeamDialog> {
|
|
final TextEditingController _nameController = TextEditingController();
|
|
final TextEditingController _imageController = TextEditingController();
|
|
String _selectedSeason = '2024/25';
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AlertDialog(
|
|
title: const Text('Nova Equipa'),
|
|
content: SingleChildScrollView(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
TextField(
|
|
controller: _nameController,
|
|
decoration: const InputDecoration(labelText: 'Nome da Equipa'),
|
|
),
|
|
const SizedBox(height: 15),
|
|
DropdownButtonFormField<String>(
|
|
value: _selectedSeason,
|
|
decoration: const InputDecoration(labelText: 'Temporada'),
|
|
items: ['2023/24', '2024/25', '2025/26'].map((s) {
|
|
return DropdownMenuItem(value: s, child: Text(s));
|
|
}).toList(),
|
|
onChanged: (val) => setState(() => _selectedSeason = val!),
|
|
),
|
|
const SizedBox(height: 15),
|
|
TextField(
|
|
controller: _imageController,
|
|
decoration: const InputDecoration(
|
|
labelText: 'URL do Logótipo ou Emoji',
|
|
hintText: 'Ex: 🏀 ou link http',
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text('Cancelar'),
|
|
),
|
|
ElevatedButton(
|
|
style: ElevatedButton.styleFrom(backgroundColor: const Color(0xFFE74C3C)),
|
|
onPressed: () {
|
|
widget.onConfirm(
|
|
_nameController.text,
|
|
_selectedSeason,
|
|
_imageController.text
|
|
);
|
|
Navigator.pop(context);
|
|
},
|
|
child: const Text('Criar', style: TextStyle(color: Colors.white)),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
} |