git lixo 2
This commit is contained in:
@@ -5,7 +5,7 @@ class GameController {
|
||||
final _supabase = Supabase.instance.client;
|
||||
|
||||
// 1. LER JOGOS (Stream em Tempo Real)
|
||||
Stream<List<Game>> get gamesStream {
|
||||
Stream<List<Game>> get gamesStream {
|
||||
return _supabase
|
||||
.from('games') // 1. Fica à escuta da tabela original (Garante o Tempo Real!)
|
||||
.stream(primaryKey: ['id'])
|
||||
@@ -21,6 +21,40 @@ Stream<List<Game>> get gamesStream {
|
||||
return viewData.map((json) => Game.fromMap(json)).toList();
|
||||
});
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 👇 NOVO: LER JOGOS COM FILTROS DE EQUIPA E TEMPORADA (MANTÉM OS LOGOS)
|
||||
// =========================================================================
|
||||
// =========================================================================
|
||||
// 👇 LER JOGOS COM FILTROS DE EQUIPA E TEMPORADA (SEM ERROS DE QUERY)
|
||||
// =========================================================================
|
||||
Stream<List<Game>> getFilteredGames({required String teamFilter, required String seasonFilter}) {
|
||||
return _supabase
|
||||
.from('games')
|
||||
.stream(primaryKey: ['id'])
|
||||
.asyncMap((event) async {
|
||||
|
||||
// 1. Começamos a query APENAS com o select (Sem o order ainda!)
|
||||
var query = _supabase.from('games_with_logos').select();
|
||||
|
||||
// 2. Se a temporada não for "Todas", aplicamos o filtro AQUI
|
||||
if (seasonFilter != 'Todas') {
|
||||
query = query.eq('season', seasonFilter);
|
||||
}
|
||||
|
||||
// 3. Executamos a query e aplicamos o ORDER BY no final
|
||||
final viewData = await query.order('game_date', ascending: false);
|
||||
|
||||
List<Game> games = viewData.map((json) => Game.fromMap(json)).toList();
|
||||
|
||||
// 4. Filtramos a equipa em memória
|
||||
if (teamFilter != 'Todas') {
|
||||
games = games.where((g) => g.myTeam == teamFilter || g.opponentTeam == teamFilter).toList();
|
||||
}
|
||||
|
||||
return games;
|
||||
});
|
||||
}
|
||||
// 2. CRIAR JOGO
|
||||
// Retorna o ID do jogo criado para podermos navegar para o placar
|
||||
Future<String?> createGame(String myTeam, String opponent, String season) async {
|
||||
|
||||
Reference in New Issue
Block a user