84 lines
2.7 KiB
Dart
84 lines
2.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../controllers/team_controller.dart';
|
|
import '../models/team_model.dart';
|
|
import '../widgets/team_widgets.dart';
|
|
|
|
class TeamsPage extends StatefulWidget {
|
|
const TeamsPage({super.key});
|
|
|
|
@override
|
|
State<TeamsPage> createState() => _TeamsPageState();
|
|
}
|
|
|
|
class _TeamsPageState extends State<TeamsPage> {
|
|
final TeamController controller = TeamController();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: const Color(0xFFF5F7FA),
|
|
|
|
// Título simples no topo (opcional, já tens a BottomNavBar)
|
|
// appBar: AppBar(title: Text("Minhas Equipas"), automaticallyImplyLeading: false),
|
|
|
|
body: StreamBuilder<List<Map<String, dynamic>>>(
|
|
stream: controller.teamsStream,
|
|
builder: (context, snapshot) {
|
|
// Estado de Loading
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
return const Center(child: CircularProgressIndicator());
|
|
}
|
|
|
|
// Estado Vazio
|
|
if (!snapshot.hasData || snapshot.data!.isEmpty) {
|
|
return Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: const [
|
|
Icon(Icons.sports_basketball_outlined, size: 60, color: Colors.grey),
|
|
SizedBox(height: 16),
|
|
Text(
|
|
'Ainda não tens equipas.',
|
|
style: TextStyle(color: Colors.grey, fontSize: 16),
|
|
),
|
|
Text(
|
|
'Clica no + para criar.',
|
|
style: TextStyle(color: Colors.grey, fontSize: 14),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
final teamsData = snapshot.data!;
|
|
|
|
// Lista de Equipas
|
|
return ListView.builder(
|
|
padding: const EdgeInsets.all(16),
|
|
itemCount: teamsData.length,
|
|
itemBuilder: (context, index) {
|
|
final team = Team.fromMap(teamsData[index]);
|
|
return TeamCard(team: team, controller: controller);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
|
|
// --- O BOTÃO FLUTUANTE QUE PEDISTE ---
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: () {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => CreateTeamDialog(
|
|
onConfirm: (name, season, imageUrl) {
|
|
controller.createTeam(name, season, imageUrl);
|
|
},
|
|
),
|
|
);
|
|
},
|
|
backgroundColor: const Color(0xFFE74C3C), // Cor Vermelha
|
|
child: const Icon(Icons.add, color: Colors.white),
|
|
),
|
|
);
|
|
}
|
|
} |