gamepage
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../controllers/team_controller.dart';
|
||||
import '../models/team_model.dart';
|
||||
import '../widgets/team_widgets.dart';
|
||||
|
||||
|
||||
class GamePage extends StatefulWidget {
|
||||
const GamePage({super.key});
|
||||
@@ -161,6 +160,8 @@ class CreateGameDialogManual extends StatefulWidget {
|
||||
|
||||
class _CreateGameDialogManualState extends State<CreateGameDialogManual> {
|
||||
final TextEditingController _seasonController = TextEditingController();
|
||||
|
||||
// Controllers para capturar o texto dos campos de pesquisa
|
||||
String _myTeamName = "";
|
||||
String _opponentName = "";
|
||||
|
||||
@@ -170,29 +171,62 @@ class _CreateGameDialogManualState extends State<CreateGameDialogManual> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Widget _buildAutocompleteField({
|
||||
// --- WIDGET DE PESQUISA (AUTOCOMPLETE) ---
|
||||
Widget _buildSearchField({
|
||||
required String label,
|
||||
required List<String> teamNames,
|
||||
required List<String> options,
|
||||
required Function(String) onSelected,
|
||||
}) {
|
||||
return Autocomplete<String>(
|
||||
optionsBuilder: (TextEditingValue textEditingValue) {
|
||||
if (textEditingValue.text.isEmpty) return const Iterable<String>.empty();
|
||||
return teamNames.where((String name) =>
|
||||
name.toLowerCase().startsWith(textEditingValue.text.toLowerCase()));
|
||||
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();
|
||||
},
|
||||
fieldViewBuilder: (context, fieldController, focusNode, onFieldSubmitted) {
|
||||
// --- 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: fieldController,
|
||||
controller: fieldTextController,
|
||||
focusNode: focusNode,
|
||||
onChanged: (value) => onSelected(value),
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
prefixIcon: const Icon(Icons.shield, size: 20, color: Color(0xFFE74C3C)),
|
||||
border: const OutlineInputBorder(),
|
||||
prefixIcon: const Icon(Icons.search, color: Color(0xFFE74C3C)),
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(10)),
|
||||
filled: true,
|
||||
fillColor: Colors.white,
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -204,39 +238,46 @@ class _CreateGameDialogManualState extends State<CreateGameDialogManual> {
|
||||
return StreamBuilder<List<Map<String, dynamic>>>(
|
||||
stream: widget.controller.teamsStream,
|
||||
builder: (context, snapshot) {
|
||||
List<String> existingTeamNames = [];
|
||||
// Lista de nomes das equipas que vêm da TeamsPage
|
||||
List<String> teamList = [];
|
||||
if (snapshot.hasData) {
|
||||
existingTeamNames = snapshot.data!.map((t) => t['name'].toString()).toList();
|
||||
teamList = snapshot.data!.map((t) => t['name'].toString()).toList();
|
||||
}
|
||||
|
||||
return AlertDialog(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||
title: const Text('Criar Novo Jogo', style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
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: const InputDecoration(
|
||||
labelText: 'Temporada / Época',
|
||||
prefixIcon: Icon(Icons.calendar_today, size: 20, color: Color(0xFFE74C3C)),
|
||||
border: OutlineInputBorder(),
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Temporada',
|
||||
prefixIcon: const Icon(Icons.calendar_today, size: 20),
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(10)),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
_buildAutocompleteField(
|
||||
|
||||
// Pesquisa: Minha Equipa
|
||||
_buildSearchField(
|
||||
label: "A Minha Equipa",
|
||||
teamNames: existingTeamNames,
|
||||
options: teamList,
|
||||
onSelected: (val) => _myTeamName = val,
|
||||
),
|
||||
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 10),
|
||||
child: Text("VS", style: TextStyle(fontWeight: FontWeight.bold, color: Colors.grey)),
|
||||
padding: EdgeInsets.symmetric(vertical: 15),
|
||||
child: Text("VS", style: TextStyle( color: Colors.grey, fontSize: 18)),
|
||||
),
|
||||
_buildAutocompleteField(
|
||||
|
||||
// Pesquisa: Equipa Adversária
|
||||
_buildSearchField(
|
||||
label: "Equipa Adversária",
|
||||
teamNames: existingTeamNames,
|
||||
options: teamList,
|
||||
onSelected: (val) => _opponentName = val,
|
||||
),
|
||||
],
|
||||
@@ -247,16 +288,17 @@ class _CreateGameDialogManualState extends State<CreateGameDialogManual> {
|
||||
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) {
|
||||
// Aqui podes adicionar a lógica para guardar o jogo no controller
|
||||
print("Jogo criado: $_myTeamName vs $_opponentName na época ${_seasonController.text}");
|
||||
// Lógica para iniciar o jogo
|
||||
print("Iniciando: $_myTeamName VS $_opponentName");
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
child: const Text('CRIAR', style: TextStyle(color: Colors.white)),
|
||||
child: const Text('CRIAR JOGO', style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user