142 lines
5.3 KiB
Dart
142 lines
5.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../models/team_model.dart';
|
|
import '../models/person_model.dart';
|
|
import '../controllers/stats_controller.dart';
|
|
import '../widgets/stats_widgets.dart';
|
|
|
|
class TeamStatsPage extends StatelessWidget {
|
|
final Team team;
|
|
// Agora este controller já tem o método getMembers
|
|
final StatsController _controller = StatsController();
|
|
|
|
TeamStatsPage({super.key, required this.team});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: const Color(0xFFF5F7FA),
|
|
body: Column(
|
|
children: [
|
|
// Certifica-te que tens o StatsHeader no ficheiro stats_widgets.dart
|
|
StatsHeader(team: team),
|
|
Expanded(
|
|
child: StreamBuilder<List<Person>>(
|
|
// AGORA ISTO VAI FUNCIONAR:
|
|
stream: _controller.getMembers(team.id),
|
|
builder: (context, snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
return const Center(child: CircularProgressIndicator());
|
|
}
|
|
|
|
if (snapshot.hasError) {
|
|
return Center(child: Text('Erro: ${snapshot.error}'));
|
|
}
|
|
|
|
final members = snapshot.data ?? [];
|
|
if (members.isEmpty) {
|
|
return const Center(child: Text("Sem membros nesta equipa."));
|
|
}
|
|
|
|
final coaches = members.where((m) => m.type == 'Treinador').toList();
|
|
final players = members.where((m) => m.type == 'Jogador').toList();
|
|
|
|
return SingleChildScrollView(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const SummaryCard(), // Confirma se tens este widget
|
|
const SizedBox(height: 30),
|
|
if (coaches.isNotEmpty) ...[
|
|
_buildSectionTitle("Treinadores"),
|
|
...coaches.map((c) => _buildPersonCard(context, c, isCoach: true)),
|
|
const SizedBox(height: 30),
|
|
],
|
|
if (players.isNotEmpty) ...[
|
|
_buildSectionTitle("Jogadores"),
|
|
...players.map((p) => _buildPersonCard(context, p, isCoach: false)),
|
|
],
|
|
const SizedBox(height: 80),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: () => _controller.showAddPersonDialog(context, team.id),
|
|
backgroundColor: const Color(0xFF00C853),
|
|
child: const Icon(Icons.add, color: Colors.white),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildPersonCard(BuildContext context, Person person, {required bool isCoach}) {
|
|
return Card(
|
|
margin: const EdgeInsets.only(top: 12),
|
|
elevation: 2,
|
|
color: isCoach ? const Color(0xFFFFF9C4) : Colors.white,
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
|
child: ListTile(
|
|
leading: isCoach
|
|
? const CircleAvatar(radius: 25, backgroundColor: Colors.orange, child: Icon(Icons.person, color: Colors.white))
|
|
: Container(
|
|
width: 50, height: 50,
|
|
alignment: Alignment.center,
|
|
decoration: BoxDecoration(color: Colors.blue.withOpacity(0.1), borderRadius: BorderRadius.circular(10)),
|
|
child: Text(person.number, style: const TextStyle(color: Colors.blue, fontWeight: FontWeight.bold, fontSize: 18)),
|
|
),
|
|
title: Text(person.name, style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 17)),
|
|
trailing: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
IconButton(
|
|
icon: const Icon(Icons.edit_outlined, size: 24, color: Colors.blue),
|
|
onPressed: () => _controller.showEditPersonDialog(context, team.id, person),
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.delete_outline, size: 24, color: Colors.red),
|
|
onPressed: () => _confirmDelete(context, person),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
void _confirmDelete(BuildContext context, Person person) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: const Text("Eliminar?"),
|
|
content: Text("Queres mesmo remover ${person.name}?"),
|
|
actions: [
|
|
TextButton(onPressed: () => Navigator.pop(context), child: const Text("Cancelar")),
|
|
TextButton(
|
|
onPressed: () {
|
|
_controller.deletePerson(team.id, person.id);
|
|
Navigator.pop(context);
|
|
},
|
|
child: const Text("Eliminar", style: TextStyle(color: Colors.red)),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildSectionTitle(String title) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(title, style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Color(0xFF2C3E50))),
|
|
const SizedBox(height: 10),
|
|
const Divider(),
|
|
],
|
|
);
|
|
}
|
|
} |