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