ndk
This commit is contained in:
139
lib/pages/PlacarPage.dart
Normal file
139
lib/pages/PlacarPage.dart
Normal file
@@ -0,0 +1,139 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class PlacarPage extends StatefulWidget {
|
||||
final String gameId;
|
||||
final String myTeam;
|
||||
final String opponentTeam;
|
||||
|
||||
const PlacarPage({
|
||||
super.key,
|
||||
required this.gameId,
|
||||
required this.myTeam,
|
||||
required this.opponentTeam,
|
||||
});
|
||||
|
||||
@override
|
||||
State<PlacarPage> createState() => _PlacarPageState();
|
||||
}
|
||||
|
||||
class _PlacarPageState extends State<PlacarPage> {
|
||||
int _myScore = 0;
|
||||
int _opponentScore = 0;
|
||||
|
||||
// Lógica do Tempo (Exemplo: 10 minutos)
|
||||
Duration _duration = const Duration(minutes: 10);
|
||||
Timer? _timer;
|
||||
bool _isRunning = false;
|
||||
|
||||
void _toggleTimer() {
|
||||
if (_isRunning) {
|
||||
_timer?.cancel();
|
||||
} else {
|
||||
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||
if (_duration.inSeconds > 0) {
|
||||
setState(() => _duration -= const Duration(seconds: 1));
|
||||
} else {
|
||||
_timer?.cancel();
|
||||
setState(() => _isRunning = false);
|
||||
}
|
||||
});
|
||||
}
|
||||
setState(() => _isRunning = !_isRunning);
|
||||
}
|
||||
|
||||
String _formatTime(Duration d) {
|
||||
return "${d.inMinutes.toString().padLeft(2, '0')}:${d.inSeconds.remainder(60).toString().padLeft(2, '0')}";
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFF121212),
|
||||
appBar: AppBar(
|
||||
title: const Text("Placar Live"),
|
||||
backgroundColor: Colors.transparent,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
const SizedBox(height: 20),
|
||||
// Cronómetro
|
||||
GestureDetector(
|
||||
onTap: _toggleTimer,
|
||||
child: Text(
|
||||
_formatTime(_duration),
|
||||
style: const TextStyle(color: Colors.white, fontSize: 75, fontWeight: FontWeight.bold, fontFamily: 'monospace'),
|
||||
),
|
||||
),
|
||||
const Text("CLIQUE NO TEMPO PARA INICIAR/PAUSAR", style: TextStyle(color: Colors.grey, fontSize: 10)),
|
||||
|
||||
Expanded(
|
||||
child: Row(
|
||||
children: [
|
||||
// Minha Equipa
|
||||
_buildTeamSide(widget.myTeam, _myScore, (p) => setState(() => _myScore += p), const Color(0xFFE74C3C)),
|
||||
// Divisor
|
||||
Container(width: 1, color: Colors.white24, margin: const EdgeInsets.symmetric(vertical: 40)),
|
||||
// Adversário
|
||||
_buildTeamSide(widget.opponentTeam, _opponentScore, (p) => setState(() => _opponentScore += p), Colors.blueGrey),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Botão Finalizar
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.green,
|
||||
minimumSize: const Size(double.infinity, 50),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15)),
|
||||
),
|
||||
onPressed: () {
|
||||
// Aqui podes adicionar a lógica para salvar o resultado final no Controller
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text("FINALIZAR PARTIDA", style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTeamSide(String name, int score, Function(int) onAdd, Color color) {
|
||||
return Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(name, textAlign: TextAlign.center, style: const TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 10),
|
||||
Text("$score", style: TextStyle(color: color, fontSize: 80, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 30),
|
||||
// Botões de Pontuação
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [1, 2, 3].map((p) => Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
child: InkWell(
|
||||
onTap: () => onAdd(p),
|
||||
child: CircleAvatar(
|
||||
backgroundColor: color.withOpacity(0.2),
|
||||
child: Text("+$p", style: TextStyle(color: color, fontWeight: FontWeight.bold)),
|
||||
),
|
||||
),
|
||||
)).toList(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../controllers/game_controller.dart';
|
||||
import '../controllers/team_controller.dart';
|
||||
|
||||
import '../models/game_model.dart';
|
||||
import '../widgets/game_widgets.dart';
|
||||
|
||||
class GamePage extends StatefulWidget {
|
||||
const GamePage({super.key});
|
||||
@@ -10,103 +12,17 @@ class GamePage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _GamePageState extends State<GamePage> {
|
||||
final TeamController controller = TeamController();
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
|
||||
String _selectedSeasonFilter = 'Todas';
|
||||
String _currentSort = 'Recentes';
|
||||
String _searchQuery = '';
|
||||
// Criamos as instâncias dos controllers
|
||||
final GameController gameController = GameController();
|
||||
final TeamController teamController = TeamController();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchController.dispose();
|
||||
// É importante fechar os streams quando a página sai da memória
|
||||
gameController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _showCreateGameDialog(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return CreateGameDialogManual(controller: controller);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _showFilterDialog(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return StatefulBuilder(
|
||||
builder: (context, setModalState) {
|
||||
return AlertDialog(
|
||||
backgroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||
title: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text("Filtros",
|
||||
style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold, fontSize: 18)
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close, color: Colors.black, size: 20),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
)
|
||||
],
|
||||
),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Divider(),
|
||||
Row(
|
||||
children: [
|
||||
_buildPopupColumn("TEMPORADA", ['Todas', '2023/24', '2024/25', '2025/26'], _selectedSeasonFilter, (val) {
|
||||
setState(() => _selectedSeasonFilter = val);
|
||||
setModalState(() {});
|
||||
}),
|
||||
const SizedBox(width: 20),
|
||||
_buildPopupColumn("ORDENAR", ['Recentes', 'Nome'], _currentSort, (val) {
|
||||
setState(() => _currentSort = val);
|
||||
setModalState(() {});
|
||||
}),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text("CONCLUÍDO", style: TextStyle(color: Color(0xFFE74C3C), fontWeight: FontWeight.bold)),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPopupColumn(String title, List<String> options, String current, Function(String) onSelect) {
|
||||
return Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(title, style: TextStyle(color: Colors.grey[700], fontSize: 11, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 12),
|
||||
...options.map((opt) => InkWell(
|
||||
onTap: () => onSelect(opt),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: Text(opt,
|
||||
style: TextStyle(
|
||||
color: current == opt ? const Color(0xFFE74C3C) : Colors.black,
|
||||
fontWeight: current == opt ? FontWeight.bold : FontWeight.normal)),
|
||||
),
|
||||
)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -115,194 +31,55 @@ class _GamePageState extends State<GamePage> {
|
||||
title: const Text("Jogos", style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
backgroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.filter_list, color: Color(0xFFE74C3C)),
|
||||
onPressed: () => _showFilterDialog(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: TextField(
|
||||
controller: _searchController,
|
||||
onChanged: (v) => setState(() => _searchQuery = v.toLowerCase()),
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Pesquisar jogo...',
|
||||
prefixIcon: const Icon(Icons.search, color: Color(0xFFE74C3C)),
|
||||
filled: true,
|
||||
fillColor: Colors.white,
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(15), borderSide: BorderSide.none),
|
||||
),
|
||||
),
|
||||
),
|
||||
const Expanded(child: Center(child: Text("Nenhum jogo registado."))),
|
||||
],
|
||||
body: StreamBuilder<List<Game>>(
|
||||
stream: gameController.gamesStream,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
if (!snapshot.hasData || snapshot.data!.isEmpty) {
|
||||
return const Center(child: Text("Nenhum jogo registado."));
|
||||
}
|
||||
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: snapshot.data!.length,
|
||||
itemBuilder: (context, index) {
|
||||
final game = snapshot.data![index];
|
||||
|
||||
// ATUALIZADO: Passamos o gameId para o card
|
||||
return GameResultCard(
|
||||
gameId: game.id,
|
||||
myTeam: game.myTeam,
|
||||
opponentTeam: game.opponentTeam,
|
||||
myScore: game.myScore,
|
||||
opponentScore: game.opponentScore,
|
||||
status: game.status,
|
||||
season: game.season,
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () => _showCreateGameDialog(context),
|
||||
backgroundColor: const Color(0xFFE74C3C),
|
||||
child: const Icon(Icons.add, color: Colors.white),
|
||||
onPressed: () => _showCreateDialog(context),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class CreateGameDialogManual extends StatefulWidget {
|
||||
final TeamController controller;
|
||||
const CreateGameDialogManual({super.key, required this.controller});
|
||||
|
||||
@override
|
||||
State<CreateGameDialogManual> createState() => _CreateGameDialogManualState();
|
||||
}
|
||||
|
||||
class _CreateGameDialogManualState extends State<CreateGameDialogManual> {
|
||||
final TextEditingController _seasonController = TextEditingController();
|
||||
|
||||
// Controllers para capturar o texto dos campos de pesquisa
|
||||
String _myTeamName = "";
|
||||
String _opponentName = "";
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_seasonController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
// --- WIDGET DE PESQUISA (AUTOCOMPLETE) ---
|
||||
Widget _buildSearchField({
|
||||
required String label,
|
||||
required List<String> options,
|
||||
required Function(String) onSelected,
|
||||
}) {
|
||||
return Autocomplete<String>(
|
||||
optionsBuilder: (TextEditingValue textEditingValue) {
|
||||
if (textEditingValue.text.isEmpty) {
|
||||
return const Iterable<String>.empty();
|
||||
}
|
||||
return options.where((String option) {
|
||||
return option.toLowerCase().contains(textEditingValue.text.toLowerCase());
|
||||
});
|
||||
},
|
||||
onSelected: (String selection) {
|
||||
onSelected(selection);
|
||||
FocusScope.of(context).unfocus();
|
||||
},
|
||||
// --- ESTE BLOCO CONSTRÓI A LISTA DE SUGESTÕES EM BAIXO ---
|
||||
optionsViewBuilder: (context, onSelected, options) {
|
||||
return Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: Material(
|
||||
elevation: 4.0,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: Container(
|
||||
width: MediaQuery.of(context).size.width * 0.7, // Ajusta à largura do dialog
|
||||
constraints: const BoxConstraints(maxHeight: 200), // Limita a altura da lista
|
||||
child: ListView.builder(
|
||||
padding: EdgeInsets.zero,
|
||||
shrinkWrap: true,
|
||||
itemCount: options.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
final String option = options.elementAt(index);
|
||||
return ListTile(
|
||||
title: Text(option),
|
||||
onTap: () => onSelected(option),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
fieldViewBuilder: (context, fieldTextController, focusNode, onFieldSubmitted) {
|
||||
return TextField(
|
||||
controller: fieldTextController,
|
||||
focusNode: focusNode,
|
||||
onChanged: (value) => onSelected(value),
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
prefixIcon: const Icon(Icons.search, color: Color(0xFFE74C3C)),
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(10)),
|
||||
filled: true,
|
||||
fillColor: Colors.white,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return StreamBuilder<List<Map<String, dynamic>>>(
|
||||
stream: widget.controller.teamsStream,
|
||||
builder: (context, snapshot) {
|
||||
// Lista de nomes das equipas que vêm da TeamsPage
|
||||
List<String> teamList = [];
|
||||
if (snapshot.hasData) {
|
||||
teamList = snapshot.data!.map((t) => t['name'].toString()).toList();
|
||||
}
|
||||
|
||||
return AlertDialog(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||
title: const Text('Configurar Partida', style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Campo da Temporada
|
||||
TextField(
|
||||
controller: _seasonController,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Temporada',
|
||||
prefixIcon: const Icon(Icons.calendar_today, size: 20),
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(10)),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// Pesquisa: Minha Equipa
|
||||
_buildSearchField(
|
||||
label: "A Minha Equipa",
|
||||
options: teamList,
|
||||
onSelected: (val) => _myTeamName = val,
|
||||
),
|
||||
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 15),
|
||||
child: Text("VS", style: TextStyle( color: Colors.grey, fontSize: 18)),
|
||||
),
|
||||
|
||||
// Pesquisa: Equipa Adversária
|
||||
_buildSearchField(
|
||||
label: "Equipa Adversária",
|
||||
options: teamList,
|
||||
onSelected: (val) => _opponentName = val,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(context), child: const Text('CANCELAR')),
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFFE74C3C),
|
||||
minimumSize: const Size(100, 45),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
||||
),
|
||||
onPressed: () {
|
||||
if (_myTeamName.isNotEmpty && _opponentName.isNotEmpty) {
|
||||
// Lógica para iniciar o jogo
|
||||
print("Iniciando: $_myTeamName VS $_opponentName");
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
child: const Text('CRIAR JOGO', style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
void _showCreateDialog(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => CreateGameDialogManual(
|
||||
controller: teamController,
|
||||
onConfirm: (my, opp, sea) {
|
||||
gameController.addGame(my, opp, sea);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:playmaker/screens/team_stats_page.dart';
|
||||
import '../controllers/team_controller.dart';
|
||||
import '../models/team_model.dart';
|
||||
import '../widgets/team_widgets.dart';
|
||||
@@ -24,7 +25,7 @@ class _TeamsPageState extends State<TeamsPage> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
// --- POPUP DE FILTROS (ESTILO DIALOG CENTRAL) ---
|
||||
// --- POPUP DE FILTROS ---
|
||||
void _showFilterDialog(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
@@ -32,6 +33,7 @@ class _TeamsPageState extends State<TeamsPage> {
|
||||
return StatefulBuilder(
|
||||
builder: (context, setModalState) {
|
||||
return AlertDialog(
|
||||
backgroundColor: const Color(0xFF2C3E50), // 2. CORRIGIDO: Fundo escuro
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||
title: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
@@ -116,7 +118,8 @@ class _TeamsPageState extends State<TeamsPage> {
|
||||
child: Text(
|
||||
opt,
|
||||
style: TextStyle(
|
||||
color: isSelected ? const Color(0xFFE74C3C) : Colors.black,
|
||||
// 3. CORRIGIDO: Cor do texto (Branco se não selecionado, Vermelho se selecionado)
|
||||
color: isSelected ? const Color(0xFFE74C3C) : Colors.white70,
|
||||
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
|
||||
),
|
||||
),
|
||||
@@ -177,46 +180,61 @@ class _TeamsPageState extends State<TeamsPage> {
|
||||
return StreamBuilder<List<Map<String, dynamic>>>(
|
||||
stream: controller.teamsStream,
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData) return const Center(child: CircularProgressIndicator());
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
var data = snapshot.data!;
|
||||
if (!snapshot.hasData || snapshot.data!.isEmpty) {
|
||||
return const Center(child: Text("Nenhuma equipa encontrada."));
|
||||
}
|
||||
|
||||
// 1. Filtro Temporada
|
||||
var data = List<Map<String, dynamic>>.from(snapshot.data!);
|
||||
|
||||
// --- 1. FILTROS ---
|
||||
if (_selectedSeason != 'Todas') {
|
||||
data = data.where((t) => t['season'] == _selectedSeason).toList();
|
||||
}
|
||||
|
||||
// 2. Filtro Pesquisa
|
||||
if (_searchQuery.isNotEmpty) {
|
||||
data = data.where((t) => t['name'].toString().toLowerCase().contains(_searchQuery)).toList();
|
||||
}
|
||||
|
||||
// 3. Ordenação (O controller já lida com favoritos, aqui aplicamos a manual)
|
||||
if (_currentSort == 'Recentes') {
|
||||
data.sort((a, b) => b['id'].compareTo(a['id']));
|
||||
} else if (_currentSort == 'Nome') {
|
||||
data.sort((a, b) => a['name'].toString().compareTo(b['name'].toString()));
|
||||
} else if (_currentSort == 'Tamanho') {
|
||||
data.sort((a, b) {
|
||||
int countA = TeamController.members.where((m) => m['team_id'] == a['id']).length;
|
||||
int countB = TeamController.members.where((m) => m['team_id'] == b['id']).length;
|
||||
return countB.compareTo(countA);
|
||||
});
|
||||
}
|
||||
// --- 2. ORDENAÇÃO (FAVORITOS PRIMEIRO) ---
|
||||
data.sort((a, b) {
|
||||
// Apanhar o estado de favorito (tratando null como false)
|
||||
bool favA = a['is_favorite'] ?? false;
|
||||
bool favB = b['is_favorite'] ?? false;
|
||||
|
||||
if (data.isEmpty) {
|
||||
return const Center(child: Text("Nenhuma equipa encontrada."));
|
||||
}
|
||||
// REGRA 1: Favoritos aparecem sempre primeiro
|
||||
if (favA && !favB) return -1; // A sobe
|
||||
if (!favA && favB) return 1; // B sobe
|
||||
|
||||
// REGRA 2: Se o estado de favorito for igual, aplica o filtro do utilizador
|
||||
if (_currentSort == 'Nome') {
|
||||
return a['name'].toString().compareTo(b['name'].toString());
|
||||
} else { // Recentes
|
||||
return (b['created_at'] ?? '').toString().compareTo((a['created_at'] ?? '').toString());
|
||||
}
|
||||
});
|
||||
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
itemCount: data.length,
|
||||
itemBuilder: (context, index) {
|
||||
final team = Team.fromMap(data[index]);
|
||||
return TeamCard(
|
||||
team: team,
|
||||
controller: controller,
|
||||
onFavoriteTap: () => controller.toggleFavorite(team.id),
|
||||
|
||||
// Navegação para estatísticas
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => TeamStatsPage(team: team)),
|
||||
);
|
||||
},
|
||||
child: TeamCard(
|
||||
team: team,
|
||||
controller: controller,
|
||||
onFavoriteTap: () => controller.toggleFavorite(team.id, team.isFavorite),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -232,4 +250,5 @@ class _TeamsPageState extends State<TeamsPage> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user