220 lines
7.4 KiB
Dart
220 lines
7.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:playmaker/pages/PlacarPage.dart';
|
|
import '../controllers/team_controller.dart';
|
|
|
|
// --- CARD DE EXIBIÇÃO DO JOGO ---
|
|
class GameResultCard extends StatelessWidget {
|
|
final String gameId; // Adicionado para identificar o jogo no retorno
|
|
final String myTeam, opponentTeam, myScore, opponentScore, status, season;
|
|
|
|
const GameResultCard({
|
|
super.key,
|
|
required this.gameId,
|
|
required this.myTeam,
|
|
required this.opponentTeam,
|
|
required this.myScore,
|
|
required this.opponentScore,
|
|
required this.status,
|
|
required this.season,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
margin: const EdgeInsets.only(bottom: 16),
|
|
padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(20),
|
|
boxShadow: [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),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildTeamInfo(String name, Color color) {
|
|
return Column(
|
|
children: [
|
|
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)),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _buildScoreCenter(BuildContext context, String id) {
|
|
return Column(
|
|
children: [
|
|
Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
_scoreBox(myScore, Colors.green),
|
|
const Text(" : ", style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20)),
|
|
_scoreBox(opponentScore, Colors.grey),
|
|
],
|
|
),
|
|
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
|
|
},
|
|
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
|
|
),
|
|
),
|
|
style: TextButton.styleFrom(
|
|
backgroundColor: const Color(0xFFE74C3C).withOpacity(0.1),
|
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
|
visualDensity: VisualDensity.compact,
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 4),
|
|
Text(status, style: const TextStyle(fontSize: 10, color: Colors.blue, fontWeight: FontWeight.bold)),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _scoreBox(String pts, Color c) => Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
|
decoration: BoxDecoration(color: c, borderRadius: BorderRadius.circular(8)),
|
|
child: Text(pts, style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
|
|
);
|
|
}
|
|
|
|
// --- POPUP DE CRIAÇÃO ---
|
|
class CreateGameDialogManual extends StatefulWidget {
|
|
final TeamController controller;
|
|
final Function(String, String, String) onConfirm;
|
|
|
|
const CreateGameDialogManual({super.key, required this.controller, required this.onConfirm});
|
|
|
|
@override
|
|
State<CreateGameDialogManual> createState() => _CreateGameDialogManualState();
|
|
}
|
|
|
|
class _CreateGameDialogManualState extends State<CreateGameDialogManual> {
|
|
late TextEditingController _seasonController;
|
|
String _myTeamName = "";
|
|
String _opponentName = "";
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_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)}";
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
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: [
|
|
TextField(
|
|
controller: _seasonController,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Temporada',
|
|
border: OutlineInputBorder(),
|
|
prefixIcon: Icon(Icons.calendar_today, size: 20),
|
|
),
|
|
),
|
|
const SizedBox(height: 15),
|
|
_buildSearch(label: "Minha Equipa", onSelect: (v) => _myTeamName = v),
|
|
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),
|
|
],
|
|
),
|
|
),
|
|
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,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
},
|
|
child: const Text('CRIAR', style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _buildSearch({required String label, required Function(String) onSelect}) {
|
|
return StreamBuilder<List<Map<String, dynamic>>>(
|
|
stream: widget.controller.teamsStream,
|
|
builder: (context, snapshot) {
|
|
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()
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
} |