quero que ao voltar para o jogo ele esteja igual quando eu sai
This commit is contained in:
@@ -24,36 +24,60 @@ class _GamePageState extends State<GamePage> {
|
||||
backgroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
),
|
||||
body: StreamBuilder<List<Game>>(
|
||||
// LÊ DIRETAMENTE DO SUPABASE
|
||||
stream: gameController.gamesStream,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
if (snapshot.hasError) {
|
||||
return Center(child: Text("Erro: ${snapshot.error}"));
|
||||
}
|
||||
// 1º STREAM: Lemos as equipas para ter as imagens
|
||||
body: StreamBuilder<List<Map<String, dynamic>>>(
|
||||
stream: teamController.teamsStream,
|
||||
builder: (context, teamSnapshot) {
|
||||
final List<Map<String, dynamic>> teamsList = teamSnapshot.data ?? [];
|
||||
|
||||
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];
|
||||
// 2º STREAM: Lemos os jogos
|
||||
return StreamBuilder<List<Game>>(
|
||||
stream: gameController.gamesStream,
|
||||
builder: (context, gameSnapshot) {
|
||||
if (gameSnapshot.connectionState == ConnectionState.waiting && teamsList.isEmpty) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
return GameResultCard(
|
||||
gameId: game.id,
|
||||
myTeam: game.myTeam,
|
||||
opponentTeam: game.opponentTeam,
|
||||
myScore: game.myScore,
|
||||
opponentScore: game.opponentScore,
|
||||
status: game.status,
|
||||
season: game.season,
|
||||
if (gameSnapshot.hasError) {
|
||||
return Center(child: Text("Erro: ${gameSnapshot.error}"));
|
||||
}
|
||||
|
||||
if (!gameSnapshot.hasData || gameSnapshot.data!.isEmpty) {
|
||||
return const Center(child: Text("Nenhum jogo registado."));
|
||||
}
|
||||
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: gameSnapshot.data!.length,
|
||||
itemBuilder: (context, index) {
|
||||
final game = gameSnapshot.data![index];
|
||||
|
||||
// --- LÓGICA PARA ENCONTRAR A IMAGEM PELO NOME ---
|
||||
String? myLogo;
|
||||
String? oppLogo;
|
||||
|
||||
for (var team in teamsList) {
|
||||
if (team['name'] == game.myTeam) {
|
||||
myLogo = team['image_url'];
|
||||
}
|
||||
if (team['name'] == game.opponentTeam) {
|
||||
oppLogo = team['image_url'];
|
||||
}
|
||||
}
|
||||
|
||||
// Agora já passamos as imagens para o cartão!
|
||||
return GameResultCard(
|
||||
gameId: game.id,
|
||||
myTeam: game.myTeam,
|
||||
opponentTeam: game.opponentTeam,
|
||||
myScore: game.myScore,
|
||||
opponentScore: game.opponentScore,
|
||||
status: game.status,
|
||||
season: game.season,
|
||||
myTeamLogo: myLogo, // <-- IMAGEM DA TUA EQUIPA
|
||||
opponentTeamLogo: oppLogo, // <-- IMAGEM DA EQUIPA ADVERSÁRIA
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -72,7 +96,7 @@ class _GamePageState extends State<GamePage> {
|
||||
context: context,
|
||||
builder: (context) => CreateGameDialogManual(
|
||||
teamController: teamController,
|
||||
gameController: gameController, // Passamos o controller para fazer o insert
|
||||
gameController: gameController,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user