stats page pagina melhrar
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:playmaker/classe/home.config.dart';
|
||||
import 'package:playmaker/controllers/team_controllers.dart';
|
||||
import 'package:playmaker/grafico%20de%20pizza/grafico.dart';
|
||||
import 'package:playmaker/pages/teams_page.dart';
|
||||
// Certifica-te que o caminho do controller está correto:
|
||||
|
||||
class HomeScreen extends StatefulWidget {
|
||||
const HomeScreen({super.key});
|
||||
@@ -12,19 +13,20 @@ class HomeScreen extends StatefulWidget {
|
||||
|
||||
class _HomeScreenState extends State<HomeScreen> {
|
||||
int _selectedIndex = 0;
|
||||
|
||||
// 1. Instanciar o Controller para aceder ao Supabase
|
||||
final TeamController _teamController = TeamController();
|
||||
|
||||
// Lista de Widgets para cada aba
|
||||
// O IndexedStack vai alternar entre estes 4 widgets
|
||||
late final List<Widget> _pages;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_pages = [
|
||||
_buildHomeContent(), // Index 0
|
||||
const Center(child: Text('Tela de Jogo')), // Index 1
|
||||
const TeamsPage(), // Index 2 (TUA TELA DE EQUIPAS)
|
||||
const Center(child: Text('Tela de Status')), // Index 3
|
||||
_buildHomeContent(), // Index 0: Home
|
||||
const Center(child: Text('Tela de Jogo')), // Index 1: Jogo
|
||||
_buildTeamsContent(), // Index 2: Equipas (O teu StreamBuilder entra aqui)
|
||||
const Center(child: Text('Tela de Status')), // Index 3: Status
|
||||
];
|
||||
}
|
||||
|
||||
@@ -34,8 +36,6 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
//home
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -50,7 +50,6 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
),
|
||||
),
|
||||
|
||||
// O IndexedStack mantém todas as páginas "vivas" mas só mostra uma
|
||||
body: IndexedStack(
|
||||
index: _selectedIndex,
|
||||
children: _pages,
|
||||
@@ -91,6 +90,65 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
|
||||
// --- WIDGETS DE CONTEÚDO ---
|
||||
|
||||
// 2. O teu StreamBuilder foi movido para aqui
|
||||
Widget _buildTeamsContent() {
|
||||
return StreamBuilder<List<Map<String, dynamic>>>(
|
||||
stream: _teamController.teamsStream,
|
||||
builder: (context, snapshot) {
|
||||
// Verificar estado de carregamento
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
// Verificar erros ou lista vazia
|
||||
if (snapshot.hasError) {
|
||||
return Center(child: Text("Erro: ${snapshot.error}"));
|
||||
}
|
||||
if (!snapshot.hasData || snapshot.data!.isEmpty) {
|
||||
return const Center(child: Text("Ainda não tens equipas."));
|
||||
}
|
||||
|
||||
// Obter dados (Lista simples do Supabase)
|
||||
final teams = snapshot.data!;
|
||||
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: teams.length,
|
||||
itemBuilder: (context, index) {
|
||||
final team = teams[index];
|
||||
|
||||
// Construção do Card da Equipa
|
||||
return Card(
|
||||
elevation: 2,
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
child: ListTile(
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: HomeConfig.primaryColor,
|
||||
child: Text(
|
||||
team['name'][0].toUpperCase(),
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
team['name'],
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
subtitle: Text("Época: ${team['season']}"),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.delete, color: Colors.red),
|
||||
onPressed: () {
|
||||
// Confirmação antes de apagar (Opcional, mas recomendado)
|
||||
_teamController.deleteTeam(team['id']);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHomeContent() {
|
||||
return SingleChildScrollView(
|
||||
child: Padding(
|
||||
|
||||
Reference in New Issue
Block a user