fazer a tela de jogo ta tudo no PlacarPage
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:playmaker/pages/PlacarPage.dart';
|
||||
import 'package:playmaker/pages/PlacarPage.dart'; // Garante que o import está correto
|
||||
import '../controllers/team_controller.dart';
|
||||
import '../controllers/game_controller.dart'; // Import necessário
|
||||
|
||||
// --- CARD DE EXIBIÇÃO DO JOGO ---
|
||||
// --- CARD DE EXIBIÇÃO DO JOGO (Mantém-se quase igual) ---
|
||||
class GameResultCard extends StatelessWidget {
|
||||
final String gameId; // Adicionado para identificar o jogo no retorno
|
||||
final String gameId;
|
||||
final String myTeam, opponentTeam, myScore, opponentScore, status, season;
|
||||
|
||||
const GameResultCard({
|
||||
@@ -26,15 +27,14 @@ class GameResultCard extends StatelessWidget {
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
boxShadow: [BoxShadow(color: Colors.black12, blurRadius: 10)],
|
||||
boxShadow: const [BoxShadow(color: Colors.black12, blurRadius: 10)],
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
_buildTeamInfo(myTeam, const Color(0xFFE74C3C)),
|
||||
// Agora passamos o context e o gameId para o centro
|
||||
_buildScoreCenter(context, gameId),
|
||||
_buildTeamInfo(opponentTeam, Colors.black87),
|
||||
Expanded(child: _buildTeamInfo(myTeam, const Color(0xFFE74C3C))),
|
||||
_buildScoreCenter(context, gameId),
|
||||
Expanded(child: _buildTeamInfo(opponentTeam, Colors.black87)),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -43,12 +43,13 @@ class GameResultCard extends StatelessWidget {
|
||||
Widget _buildTeamInfo(String name, Color color) {
|
||||
return Column(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
backgroundColor: color,
|
||||
child: const Icon(Icons.shield, color: Colors.white)
|
||||
),
|
||||
CircleAvatar(backgroundColor: color, child: const Icon(Icons.shield, color: Colors.white)),
|
||||
const SizedBox(height: 4),
|
||||
Text(name, style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 12)),
|
||||
Text(name,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 12),
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -65,22 +66,22 @@ class GameResultCard extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// BOTÃO PARA RETORNAR AO JOGO
|
||||
TextButton.icon(
|
||||
onPressed: () {
|
||||
print("Navegando para o marcador do jogo: $id");
|
||||
// Aqui faremos a navegação para a página do marcador em breve
|
||||
// NAVEGAÇÃO PARA O PLACAR (Usando o ID real)
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => PlacarPage(
|
||||
gameId: id,
|
||||
myTeam: myTeam,
|
||||
opponentTeam: opponentTeam,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.play_circle_fill, size: 16, color: Color(0xFFE74C3C)),
|
||||
label: const Text(
|
||||
"RETORNAR",
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
color: Color(0xFFE74C3C),
|
||||
fontWeight: FontWeight.bold
|
||||
),
|
||||
),
|
||||
label: const Text("RETORNAR", style: TextStyle(fontSize: 10, color: Color(0xFFE74C3C), fontWeight: FontWeight.bold)),
|
||||
style: TextButton.styleFrom(
|
||||
backgroundColor: const Color(0xFFE74C3C).withOpacity(0.1),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
@@ -88,7 +89,6 @@ class GameResultCard extends StatelessWidget {
|
||||
visualDensity: VisualDensity.compact,
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 4),
|
||||
Text(status, style: const TextStyle(fontSize: 10, color: Colors.blue, fontWeight: FontWeight.bold)),
|
||||
],
|
||||
@@ -102,12 +102,16 @@ class GameResultCard extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
// --- POPUP DE CRIAÇÃO ---
|
||||
// --- POPUP DE CRIAÇÃO (MODIFICADO PARA SUPABASE) ---
|
||||
class CreateGameDialogManual extends StatefulWidget {
|
||||
final TeamController controller;
|
||||
final Function(String, String, String) onConfirm;
|
||||
final TeamController teamController;
|
||||
final GameController gameController; // Recebemos o controller do jogo
|
||||
|
||||
const CreateGameDialogManual({super.key, required this.controller, required this.onConfirm});
|
||||
const CreateGameDialogManual({
|
||||
super.key,
|
||||
required this.teamController,
|
||||
required this.gameController
|
||||
});
|
||||
|
||||
@override
|
||||
State<CreateGameDialogManual> createState() => _CreateGameDialogManualState();
|
||||
@@ -115,8 +119,10 @@ class CreateGameDialogManual extends StatefulWidget {
|
||||
|
||||
class _CreateGameDialogManualState extends State<CreateGameDialogManual> {
|
||||
late TextEditingController _seasonController;
|
||||
String _myTeamName = "";
|
||||
String _opponentName = "";
|
||||
final TextEditingController _myTeamController = TextEditingController();
|
||||
final TextEditingController _opponentController = TextEditingController();
|
||||
|
||||
bool _isLoading = false; // Para mostrar loading no botão
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -124,12 +130,6 @@ class _CreateGameDialogManualState extends State<CreateGameDialogManual> {
|
||||
_seasonController = TextEditingController(text: _calculateSeason());
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_seasonController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
String _calculateSeason() {
|
||||
final now = DateTime.now();
|
||||
return now.month >= 7 ? "${now.year}/${(now.year + 1).toString().substring(2)}" : "${now.year - 1}/${now.year.toString().substring(2)}";
|
||||
@@ -146,73 +146,102 @@ class _CreateGameDialogManualState extends State<CreateGameDialogManual> {
|
||||
children: [
|
||||
TextField(
|
||||
controller: _seasonController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Temporada',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.calendar_today, size: 20),
|
||||
),
|
||||
decoration: const InputDecoration(labelText: 'Temporada', border: OutlineInputBorder(), prefixIcon: Icon(Icons.calendar_today)),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
_buildSearch(label: "Minha Equipa", onSelect: (v) => _myTeamName = v),
|
||||
|
||||
// Usamos Autocomplete para equipas (Assumindo que TeamController já é Supabase)
|
||||
_buildSearch(label: "Minha Equipa", controller: _myTeamController),
|
||||
|
||||
const Padding(padding: EdgeInsets.symmetric(vertical: 8), child: Text("VS", style: TextStyle(fontWeight: FontWeight.bold, color: Colors.grey))),
|
||||
_buildSearch(label: "Adversário", onSelect: (v) => _opponentName = v),
|
||||
|
||||
_buildSearch(label: "Adversário", controller: _opponentController),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(context), child: const Text('CANCELAR')),
|
||||
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFFE74C3C),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
||||
),
|
||||
onPressed: () {
|
||||
if (_myTeamName.isNotEmpty && _opponentName.isNotEmpty) {
|
||||
// 1. Criar um ID único para este jogo
|
||||
final String newGameId = DateTime.now().toString();
|
||||
|
||||
// 2. Notificar a GamePage para criar o card (via onConfirm)
|
||||
widget.onConfirm(_myTeamName, _opponentName, _seasonController.text);
|
||||
|
||||
// 3. Fechar o popup de criação
|
||||
Navigator.pop(context);
|
||||
|
||||
// 4. Ir direto para a tela do marcador de pontos
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => PlacarPage(
|
||||
gameId: newGameId,
|
||||
myTeam: _myTeamName,
|
||||
opponentTeam: _opponentName,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFFE74C3C),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
||||
),
|
||||
onPressed: _isLoading ? null : () async {
|
||||
if (_myTeamController.text.isNotEmpty && _opponentController.text.isNotEmpty) {
|
||||
setState(() => _isLoading = true);
|
||||
|
||||
// 1. CRIAR NO SUPABASE E OBTER O ID REAL
|
||||
String? newGameId = await widget.gameController.createGame(
|
||||
_myTeamController.text,
|
||||
_opponentController.text,
|
||||
_seasonController.text,
|
||||
);
|
||||
|
||||
setState(() => _isLoading = false);
|
||||
|
||||
if (newGameId != null && context.mounted) {
|
||||
// 2. Fechar Popup
|
||||
Navigator.pop(context);
|
||||
|
||||
// 3. Ir para o Placar com o ID real do banco
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => PlacarPage(
|
||||
gameId: newGameId,
|
||||
myTeam: _myTeamController.text,
|
||||
opponentTeam: _opponentController.text,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
child: _isLoading
|
||||
? const SizedBox(width: 20, height: 20, child: CircularProgressIndicator(color: Colors.white, strokeWidth: 2))
|
||||
: const Text('CRIAR', style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: const Text('CRIAR', style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSearch({required String label, required Function(String) onSelect}) {
|
||||
Widget _buildSearch({required String label, required TextEditingController controller}) {
|
||||
return StreamBuilder<List<Map<String, dynamic>>>(
|
||||
stream: widget.controller.teamsStream,
|
||||
stream: widget.teamController.teamsStream,
|
||||
builder: (context, snapshot) {
|
||||
List<String> teamList = snapshot.hasData ? snapshot.data!.map((t) => t['name'].toString()).toList() : [];
|
||||
List<String> teamList = snapshot.hasData
|
||||
? snapshot.data!.map((t) => t['name'].toString()).toList()
|
||||
: [];
|
||||
|
||||
return Autocomplete<String>(
|
||||
optionsBuilder: (val) => val.text.isEmpty ? [] : teamList.where((t) => t.toLowerCase().contains(val.text.toLowerCase())),
|
||||
fieldViewBuilder: (ctx, ctrl, node, submit) => TextField(
|
||||
controller: ctrl,
|
||||
focusNode: node,
|
||||
onChanged: onSelect,
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
prefixIcon: const Icon(Icons.search),
|
||||
border: const OutlineInputBorder()
|
||||
),
|
||||
),
|
||||
optionsBuilder: (val) {
|
||||
if (val.text.isEmpty) return const Iterable<String>.empty();
|
||||
return teamList.where((t) => t.toLowerCase().contains(val.text.toLowerCase()));
|
||||
},
|
||||
onSelected: (String selection) {
|
||||
controller.text = selection;
|
||||
},
|
||||
fieldViewBuilder: (ctx, txtCtrl, node, submit) {
|
||||
// Sincronizar o controller interno do Autocomplete com o nosso controller externo
|
||||
if (txtCtrl.text.isEmpty && controller.text.isNotEmpty) {
|
||||
txtCtrl.text = controller.text;
|
||||
}
|
||||
// Importante: Guardar o valor escrito mesmo que não selecionado da lista
|
||||
txtCtrl.addListener(() {
|
||||
controller.text = txtCtrl.text;
|
||||
});
|
||||
|
||||
return TextField(
|
||||
controller: txtCtrl,
|
||||
focusNode: node,
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
prefixIcon: const Icon(Icons.search),
|
||||
border: const OutlineInputBorder()
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user