Conflitos resolvidos: mantido o código local
This commit is contained in:
@@ -1,91 +1,77 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:playmaker/pages/PlacarPage.dart';
|
||||
import 'package:playmaker/classe/theme.dart';
|
||||
import '../controllers/game_controller.dart';
|
||||
import '../controllers/team_controller.dart';
|
||||
import '../controllers/game_controller.dart';
|
||||
import '../models/game_model.dart';
|
||||
import '../utils/size_extension.dart';
|
||||
import '../utils/size_extension.dart'; // 👇 NOVO SUPERPODER AQUI TAMBÉM!
|
||||
|
||||
// --- CARD DE EXIBIÇÃO DO JOGO ---
|
||||
class GameResultCard extends StatelessWidget {
|
||||
final String gameId, myTeam, opponentTeam, myScore, opponentScore, status, season;
|
||||
final String? myTeamLogo, opponentTeamLogo;
|
||||
final double sf;
|
||||
final String? myTeamLogo, opponentTeamLogo;
|
||||
|
||||
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,
|
||||
this.myTeamLogo, this.opponentTeamLogo, required this.sf,
|
||||
this.myTeamLogo, this.opponentTeamLogo,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bgColor = Theme.of(context).cardTheme.color;
|
||||
final textColor = Theme.of(context).colorScheme.onSurface;
|
||||
|
||||
return Container(
|
||||
margin: EdgeInsets.only(bottom: 16 * sf),
|
||||
padding: EdgeInsets.all(16 * sf),
|
||||
decoration: BoxDecoration(
|
||||
color: bgColor,
|
||||
borderRadius: BorderRadius.circular(20 * sf),
|
||||
boxShadow: [BoxShadow(color: Colors.black12, blurRadius: 10 * sf)],
|
||||
border: Border.all(color: Colors.grey.withOpacity(0.1)),
|
||||
),
|
||||
margin: EdgeInsets.only(bottom: 16 * context.sf),
|
||||
padding: EdgeInsets.all(16 * context.sf),
|
||||
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(20 * context.sf), boxShadow: [BoxShadow(color: Colors.black12, blurRadius: 10 * context.sf)]),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(child: _buildTeamInfo(myTeam, AppTheme.primaryRed, myTeamLogo, sf, textColor)),
|
||||
_buildScoreCenter(context, gameId, sf, textColor),
|
||||
Expanded(child: _buildTeamInfo(opponentTeam, Colors.grey.shade600, opponentTeamLogo, sf, textColor)),
|
||||
Expanded(child: _buildTeamInfo(context, myTeam, const Color(0xFFE74C3C), myTeamLogo)),
|
||||
_buildScoreCenter(context, gameId),
|
||||
Expanded(child: _buildTeamInfo(context, opponentTeam, Colors.black87, opponentTeamLogo)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTeamInfo(String name, Color color, String? logoUrl, double sf, Color textColor) {
|
||||
Widget _buildTeamInfo(BuildContext context, String name, Color color, String? logoUrl) {
|
||||
return Column(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 24 * sf,
|
||||
backgroundColor: color,
|
||||
backgroundImage: (logoUrl != null && logoUrl.isNotEmpty) ? NetworkImage(logoUrl) : null,
|
||||
child: (logoUrl == null || logoUrl.isEmpty) ? Icon(Icons.shield, color: Colors.white, size: 24 * sf) : null,
|
||||
),
|
||||
SizedBox(height: 6 * sf),
|
||||
Text(name, style: TextStyle(fontWeight: FontWeight.bold, fontSize: 13 * sf, color: textColor), textAlign: TextAlign.center, overflow: TextOverflow.ellipsis, maxLines: 2),
|
||||
CircleAvatar(radius: 24 * context.sf, backgroundColor: color, backgroundImage: (logoUrl != null && logoUrl.isNotEmpty) ? NetworkImage(logoUrl) : null, child: (logoUrl == null || logoUrl.isEmpty) ? Icon(Icons.shield, color: Colors.white, size: 24 * context.sf) : null),
|
||||
SizedBox(height: 6 * context.sf),
|
||||
Text(name, style: TextStyle(fontWeight: FontWeight.bold, fontSize: 13 * context.sf), textAlign: TextAlign.center, overflow: TextOverflow.ellipsis, maxLines: 2),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildScoreCenter(BuildContext context, String id, double sf, Color textColor) {
|
||||
Widget _buildScoreCenter(BuildContext context, String id) {
|
||||
return Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_scoreBox(myScore, AppTheme.successGreen, sf),
|
||||
Text(" : ", style: TextStyle(fontWeight: FontWeight.bold, fontSize: 22 * sf, color: textColor)),
|
||||
_scoreBox(opponentScore, Colors.grey, sf),
|
||||
_scoreBox(context, myScore, Colors.green),
|
||||
Text(" : ", style: TextStyle(fontWeight: FontWeight.bold, fontSize: 22 * context.sf)),
|
||||
_scoreBox(context, opponentScore, Colors.grey),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 10 * sf),
|
||||
SizedBox(height: 10 * context.sf),
|
||||
TextButton.icon(
|
||||
onPressed: () => Navigator.push(context, MaterialPageRoute(builder: (context) => PlacarPage(gameId: id, myTeam: myTeam, opponentTeam: opponentTeam))),
|
||||
icon: Icon(Icons.play_circle_fill, size: 18 * sf, color: AppTheme.primaryRed),
|
||||
label: Text("RETORNAR", style: TextStyle(fontSize: 11 * sf, color: AppTheme.primaryRed, fontWeight: FontWeight.bold)),
|
||||
style: TextButton.styleFrom(backgroundColor: AppTheme.primaryRed.withOpacity(0.1), padding: EdgeInsets.symmetric(horizontal: 14 * sf, vertical: 8 * sf), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20 * sf)), visualDensity: VisualDensity.compact),
|
||||
icon: Icon(Icons.play_circle_fill, size: 18 * context.sf, color: const Color(0xFFE74C3C)),
|
||||
label: Text("RETORNAR", style: TextStyle(fontSize: 11 * context.sf, color: const Color(0xFFE74C3C), fontWeight: FontWeight.bold)),
|
||||
style: TextButton.styleFrom(backgroundColor: const Color(0xFFE74C3C).withOpacity(0.1), padding: EdgeInsets.symmetric(horizontal: 14 * context.sf, vertical: 8 * context.sf), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20 * context.sf)), visualDensity: VisualDensity.compact),
|
||||
),
|
||||
SizedBox(height: 6 * sf),
|
||||
Text(status, style: TextStyle(fontSize: 12 * sf, color: Colors.blue, fontWeight: FontWeight.bold)),
|
||||
SizedBox(height: 6 * context.sf),
|
||||
Text(status, style: TextStyle(fontSize: 12 * context.sf, color: Colors.blue, fontWeight: FontWeight.bold)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _scoreBox(String pts, Color c, double sf) => Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 12 * sf, vertical: 6 * sf),
|
||||
decoration: BoxDecoration(color: c, borderRadius: BorderRadius.circular(8 * sf)),
|
||||
child: Text(pts, style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 16 * sf)),
|
||||
Widget _scoreBox(BuildContext context, String pts, Color c) => Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 12 * context.sf, vertical: 6 * context.sf),
|
||||
decoration: BoxDecoration(color: c, borderRadius: BorderRadius.circular(8 * context.sf)),
|
||||
child: Text(pts, style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 16 * context.sf)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -93,9 +79,8 @@ class GameResultCard extends StatelessWidget {
|
||||
class CreateGameDialogManual extends StatefulWidget {
|
||||
final TeamController teamController;
|
||||
final GameController gameController;
|
||||
final double sf;
|
||||
|
||||
const CreateGameDialogManual({super.key, required this.teamController, required this.gameController, required this.sf});
|
||||
const CreateGameDialogManual({super.key, required this.teamController, required this.gameController});
|
||||
|
||||
@override
|
||||
State<CreateGameDialogManual> createState() => _CreateGameDialogManualState();
|
||||
@@ -121,29 +106,24 @@ class _CreateGameDialogManualState extends State<CreateGameDialogManual> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20 * widget.sf)),
|
||||
title: Text('Configurar Partida', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18 * widget.sf, color: Theme.of(context).colorScheme.onSurface)),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20 * context.sf)),
|
||||
title: Text('Configurar Partida', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18 * context.sf)),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextField(
|
||||
controller: _seasonController,
|
||||
style: TextStyle(fontSize: 14 * widget.sf, color: Theme.of(context).colorScheme.onSurface),
|
||||
decoration: InputDecoration(labelText: 'Temporada', labelStyle: TextStyle(fontSize: 14 * widget.sf), border: const OutlineInputBorder(), prefixIcon: Icon(Icons.calendar_today, size: 20 * widget.sf))
|
||||
),
|
||||
SizedBox(height: 15 * widget.sf),
|
||||
TextField(controller: _seasonController, style: TextStyle(fontSize: 14 * context.sf), decoration: InputDecoration(labelText: 'Temporada', labelStyle: TextStyle(fontSize: 14 * context.sf), border: const OutlineInputBorder(), prefixIcon: Icon(Icons.calendar_today, size: 20 * context.sf))),
|
||||
SizedBox(height: 15 * context.sf),
|
||||
_buildSearch(context, "Minha Equipa", _myTeamController),
|
||||
Padding(padding: EdgeInsets.symmetric(vertical: 10 * widget.sf), child: Text("VS", style: TextStyle(fontWeight: FontWeight.bold, color: Colors.grey, fontSize: 16 * widget.sf))),
|
||||
Padding(padding: EdgeInsets.symmetric(vertical: 10 * context.sf), child: Text("VS", style: TextStyle(fontWeight: FontWeight.bold, color: Colors.grey, fontSize: 16 * context.sf))),
|
||||
_buildSearch(context, "Adversário", _opponentController),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(context), child: Text('CANCELAR', style: TextStyle(fontSize: 14 * widget.sf, color: Colors.grey))),
|
||||
TextButton(onPressed: () => Navigator.pop(context), child: Text('CANCELAR', style: TextStyle(fontSize: 14 * context.sf))),
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(backgroundColor: AppTheme.primaryRed, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10 * widget.sf)), padding: EdgeInsets.symmetric(horizontal: 16 * widget.sf, vertical: 10 * widget.sf)),
|
||||
style: ElevatedButton.styleFrom(backgroundColor: const Color(0xFFE74C3C), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10 * context.sf)), padding: EdgeInsets.symmetric(horizontal: 16 * context.sf, vertical: 10 * context.sf)),
|
||||
onPressed: _isLoading ? null : () async {
|
||||
if (_myTeamController.text.isNotEmpty && _opponentController.text.isNotEmpty) {
|
||||
setState(() => _isLoading = true);
|
||||
@@ -155,7 +135,7 @@ class _CreateGameDialogManualState extends State<CreateGameDialogManual> {
|
||||
}
|
||||
}
|
||||
},
|
||||
child: _isLoading ? SizedBox(width: 20 * widget.sf, height: 20 * widget.sf, child: const CircularProgressIndicator(color: Colors.white, strokeWidth: 2)) : Text('CRIAR', style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 14 * widget.sf)),
|
||||
child: _isLoading ? SizedBox(width: 20 * context.sf, height: 20 * context.sf, child: const CircularProgressIndicator(color: Colors.white, strokeWidth: 2)) : Text('CRIAR', style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 14 * context.sf)),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -177,10 +157,9 @@ class _CreateGameDialogManualState extends State<CreateGameDialogManual> {
|
||||
return Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: Material(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
elevation: 4.0, borderRadius: BorderRadius.circular(8 * widget.sf),
|
||||
elevation: 4.0, borderRadius: BorderRadius.circular(8 * context.sf),
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxHeight: 250 * widget.sf, maxWidth: MediaQuery.of(context).size.width * 0.7),
|
||||
constraints: BoxConstraints(maxHeight: 250 * context.sf, maxWidth: MediaQuery.of(context).size.width * 0.7),
|
||||
child: ListView.builder(
|
||||
padding: EdgeInsets.zero, shrinkWrap: true, itemCount: options.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
@@ -188,8 +167,8 @@ class _CreateGameDialogManualState extends State<CreateGameDialogManual> {
|
||||
final String name = option['name'].toString();
|
||||
final String? imageUrl = option['image_url'];
|
||||
return ListTile(
|
||||
leading: CircleAvatar(radius: 20 * widget.sf, backgroundColor: Colors.grey.withOpacity(0.2), backgroundImage: (imageUrl != null && imageUrl.isNotEmpty) ? NetworkImage(imageUrl) : null, child: (imageUrl == null || imageUrl.isEmpty) ? Icon(Icons.shield, color: Colors.grey, size: 20 * widget.sf) : null),
|
||||
title: Text(name, style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14 * widget.sf, color: Theme.of(context).colorScheme.onSurface)),
|
||||
leading: CircleAvatar(radius: 20 * context.sf, backgroundColor: Colors.grey.shade200, backgroundImage: (imageUrl != null && imageUrl.isNotEmpty) ? NetworkImage(imageUrl) : null, child: (imageUrl == null || imageUrl.isEmpty) ? Icon(Icons.shield, color: Colors.grey, size: 20 * context.sf) : null),
|
||||
title: Text(name, style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14 * context.sf)),
|
||||
onTap: () { onSelected(option); },
|
||||
);
|
||||
},
|
||||
@@ -202,9 +181,8 @@ class _CreateGameDialogManualState extends State<CreateGameDialogManual> {
|
||||
if (txtCtrl.text.isEmpty && controller.text.isNotEmpty) txtCtrl.text = controller.text;
|
||||
txtCtrl.addListener(() { controller.text = txtCtrl.text; });
|
||||
return TextField(
|
||||
controller: txtCtrl, focusNode: node,
|
||||
style: TextStyle(fontSize: 14 * widget.sf, color: Theme.of(context).colorScheme.onSurface),
|
||||
decoration: InputDecoration(labelText: label, labelStyle: TextStyle(fontSize: 14 * widget.sf), prefixIcon: Icon(Icons.search, size: 20 * widget.sf, color: AppTheme.primaryRed)),
|
||||
controller: txtCtrl, focusNode: node, style: TextStyle(fontSize: 14 * context.sf),
|
||||
decoration: InputDecoration(labelText: label, labelStyle: TextStyle(fontSize: 14 * context.sf), prefixIcon: Icon(Icons.search, size: 20 * context.sf), border: const OutlineInputBorder()),
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -224,24 +202,20 @@ class GamePage extends StatefulWidget {
|
||||
class _GamePageState extends State<GamePage> {
|
||||
final GameController gameController = GameController();
|
||||
final TeamController teamController = TeamController();
|
||||
String selectedSeason = 'Todas';
|
||||
String selectedTeam = 'Todas';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
bool isFilterActive = selectedSeason != 'Todas' || selectedTeam != 'Todas';
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
appBar: AppBar(
|
||||
title: Text("Jogos", style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20 * context.sf)),
|
||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
backgroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
actions: [
|
||||
Padding(
|
||||
padding: EdgeInsets.only(right: 8.0 * context.sf),
|
||||
child: IconButton(
|
||||
icon: Icon(isFilterActive ? Icons.filter_list_alt : Icons.filter_list, color: isFilterActive ? AppTheme.primaryRed : Theme.of(context).colorScheme.onSurface, size: 26 * context.sf),
|
||||
icon: Icon(isFilterActive ? Icons.filter_list_alt : Icons.filter_list, color: isFilterActive ? const Color(0xFFE74C3C) : Colors.black87, size: 26 * context.sf),
|
||||
onPressed: () => _showFilterPopup(context),
|
||||
),
|
||||
)
|
||||
@@ -251,28 +225,40 @@ class _GamePageState extends State<GamePage> {
|
||||
stream: teamController.teamsStream,
|
||||
builder: (context, teamSnapshot) {
|
||||
final List<Map<String, dynamic>> teamsList = teamSnapshot.data ?? [];
|
||||
|
||||
// 2º STREAM: Lemos os jogos
|
||||
return StreamBuilder<List<Game>>(
|
||||
stream: gameController.getFilteredGames(teamFilter: selectedTeam, seasonFilter: selectedSeason),
|
||||
stream: gameController.gamesStream,
|
||||
builder: (context, gameSnapshot) {
|
||||
if (gameSnapshot.connectionState == ConnectionState.waiting && teamsList.isEmpty) return const Center(child: CircularProgressIndicator());
|
||||
if (gameSnapshot.hasError) return Center(child: Text("Erro: ${gameSnapshot.error}", style: TextStyle(fontSize: 14 * context.sf, color: Theme.of(context).colorScheme.onSurface)));
|
||||
if (gameSnapshot.hasError) return Center(child: Text("Erro: ${gameSnapshot.error}", style: TextStyle(fontSize: 14 * context.sf)));
|
||||
if (!gameSnapshot.hasData || gameSnapshot.data!.isEmpty) {
|
||||
return Center(child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [Icon(Icons.search_off, size: 48 * context.sf, color: Colors.grey.withOpacity(0.3)), SizedBox(height: 10 * context.sf), Text("Nenhum jogo encontrado.", style: TextStyle(fontSize: 14 * context.sf, color: Colors.grey))]));
|
||||
return Center(child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [Icon(Icons.search_off, size: 48 * context.sf, color: Colors.grey.shade300), SizedBox(height: 10 * context.sf), Text("Nenhum jogo encontrado.", style: TextStyle(fontSize: 14 * context.sf, color: Colors.grey.shade600))]));
|
||||
}
|
||||
|
||||
return ListView.builder(
|
||||
padding: EdgeInsets.all(16 * context.sf),
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: gameSnapshot.data!.length,
|
||||
itemBuilder: (context, index) {
|
||||
final game = gameSnapshot.data![index];
|
||||
String? myLogo, oppLogo;
|
||||
|
||||
// --- 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'];
|
||||
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, opponentTeamLogo: oppLogo,
|
||||
sf: context.sf,
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -281,53 +267,49 @@ class _GamePageState extends State<GamePage> {
|
||||
},
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
heroTag: 'add_game_btn',
|
||||
backgroundColor: AppTheme.primaryRed,
|
||||
heroTag: 'add_game_btn', // 👇 A MÁGICA ESTÁ AQUI TAMBÉM!
|
||||
backgroundColor: const Color(0xFFE74C3C),
|
||||
child: Icon(Icons.add, color: Colors.white, size: 24 * context.sf),
|
||||
onPressed: () => showDialog(context: context, builder: (context) => CreateGameDialogManual(teamController: teamController, gameController: gameController, sf: context.sf)),
|
||||
onPressed: () => showDialog(context: context, builder: (context) => CreateGameDialogManual(teamController: teamController, gameController: gameController)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showFilterPopup(BuildContext context) {
|
||||
String tempSeason = selectedSeason;
|
||||
String tempTeam = selectedTeam;
|
||||
void _showCreateDialog(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return StatefulBuilder(
|
||||
builder: (context, setPopupState) {
|
||||
return AlertDialog(
|
||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20 * context.sf)),
|
||||
title: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('Filtrar Jogos', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18 * context.sf, color: Theme.of(context).colorScheme.onSurface)),
|
||||
Text('Filtrar Jogos', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18 * context.sf)),
|
||||
IconButton(icon: const Icon(Icons.close, color: Colors.grey), onPressed: () => Navigator.pop(context), padding: EdgeInsets.zero, constraints: const BoxConstraints())
|
||||
],
|
||||
),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text("Temporada", style: TextStyle(fontSize: 12 * context.sf, color: Colors.grey, fontWeight: FontWeight.bold)),
|
||||
Text("Temporada", style: TextStyle(fontSize: 12 * context.sf, color: Colors.grey.shade600, fontWeight: FontWeight.bold)),
|
||||
SizedBox(height: 6 * context.sf),
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 12 * context.sf), decoration: BoxDecoration(color: Theme.of(context).cardTheme.color, borderRadius: BorderRadius.circular(10 * context.sf), border: Border.all(color: Colors.grey.withOpacity(0.2))),
|
||||
padding: EdgeInsets.symmetric(horizontal: 12 * context.sf), decoration: BoxDecoration(color: Colors.grey.shade100, borderRadius: BorderRadius.circular(10 * context.sf)),
|
||||
child: DropdownButtonHideUnderline(
|
||||
child: DropdownButton<String>(
|
||||
dropdownColor: Theme.of(context).colorScheme.surface,
|
||||
isExpanded: true, value: tempSeason, style: TextStyle(fontSize: 14 * context.sf, color: Theme.of(context).colorScheme.onSurface, fontWeight: FontWeight.bold),
|
||||
isExpanded: true, value: tempSeason, style: TextStyle(fontSize: 14 * context.sf, color: Colors.black87, fontWeight: FontWeight.bold),
|
||||
items: ['Todas', '2024/25', '2025/26'].map((String value) => DropdownMenuItem<String>(value: value, child: Text(value))).toList(),
|
||||
onChanged: (newValue) => setPopupState(() => tempSeason = newValue!),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 20 * context.sf),
|
||||
Text("Equipa", style: TextStyle(fontSize: 12 * context.sf, color: Colors.grey, fontWeight: FontWeight.bold)),
|
||||
Text("Equipa", style: TextStyle(fontSize: 12 * context.sf, color: Colors.grey.shade600, fontWeight: FontWeight.bold)),
|
||||
SizedBox(height: 6 * context.sf),
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 12 * context.sf), decoration: BoxDecoration(color: Theme.of(context).cardTheme.color, borderRadius: BorderRadius.circular(10 * context.sf), border: Border.all(color: Colors.grey.withOpacity(0.2))),
|
||||
padding: EdgeInsets.symmetric(horizontal: 12 * context.sf), decoration: BoxDecoration(color: Colors.grey.shade100, borderRadius: BorderRadius.circular(10 * context.sf)),
|
||||
child: StreamBuilder<List<Map<String, dynamic>>>(
|
||||
stream: teamController.teamsStream,
|
||||
builder: (context, snapshot) {
|
||||
@@ -336,8 +318,7 @@ class _GamePageState extends State<GamePage> {
|
||||
if (!teamNames.contains(tempTeam)) tempTeam = 'Todas';
|
||||
return DropdownButtonHideUnderline(
|
||||
child: DropdownButton<String>(
|
||||
dropdownColor: Theme.of(context).colorScheme.surface,
|
||||
isExpanded: true, value: tempTeam, style: TextStyle(fontSize: 14 * context.sf, color: Theme.of(context).colorScheme.onSurface, fontWeight: FontWeight.bold),
|
||||
isExpanded: true, value: tempTeam, style: TextStyle(fontSize: 14 * context.sf, color: Colors.black87, fontWeight: FontWeight.bold),
|
||||
items: teamNames.map((String value) => DropdownMenuItem<String>(value: value, child: Text(value, overflow: TextOverflow.ellipsis))).toList(),
|
||||
onChanged: (newValue) => setPopupState(() => tempTeam = newValue!),
|
||||
),
|
||||
@@ -349,7 +330,7 @@ class _GamePageState extends State<GamePage> {
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () { setState(() { selectedSeason = 'Todas'; selectedTeam = 'Todas'; }); Navigator.pop(context); }, child: Text('LIMPAR', style: TextStyle(fontSize: 12 * context.sf, color: Colors.grey))),
|
||||
ElevatedButton(style: ElevatedButton.styleFrom(backgroundColor: AppTheme.primaryRed, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10 * context.sf))), onPressed: () { setState(() { selectedSeason = tempSeason; selectedTeam = tempTeam; }); Navigator.pop(context); }, child: Text('APLICAR', style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 13 * context.sf))),
|
||||
ElevatedButton(style: ElevatedButton.styleFrom(backgroundColor: const Color(0xFFE74C3C), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10 * context.sf))), onPressed: () { setState(() { selectedSeason = tempSeason; selectedTeam = tempTeam; }); Navigator.pop(context); }, child: Text('APLICAR', style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 13 * context.sf))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import 'package:playmaker/screens/team_stats_page.dart';
|
||||
import 'package:playmaker/classe/theme.dart'; // 👇 IMPORT DO TEMA
|
||||
import '../controllers/team_controller.dart';
|
||||
import '../models/team_model.dart';
|
||||
import '../utils/size_extension.dart';
|
||||
import '../utils/size_extension.dart'; // 👇 IMPORTANTE: O TEU NOVO SUPERPODER
|
||||
|
||||
class TeamsPage extends StatefulWidget {
|
||||
const TeamsPage({super.key});
|
||||
@@ -26,6 +26,7 @@ class _TeamsPageState extends State<TeamsPage> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
// --- POPUP DE FILTROS ---
|
||||
void _showFilterDialog(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
@@ -33,14 +34,14 @@ class _TeamsPageState extends State<TeamsPage> {
|
||||
return StatefulBuilder(
|
||||
builder: (context, setModalState) {
|
||||
return AlertDialog(
|
||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||
backgroundColor: const Color(0xFF2C3E50),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20 * context.sf)),
|
||||
title: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text("Filtros de pesquisa", style: TextStyle(color: Theme.of(context).colorScheme.onSurface, fontSize: 18 * context.sf, fontWeight: FontWeight.bold)),
|
||||
Text("Filtros de pesquisa", style: TextStyle(color: Colors.white, fontSize: 18 * context.sf, fontWeight: FontWeight.bold)),
|
||||
IconButton(
|
||||
icon: Icon(Icons.close, color: Colors.grey, size: 20 * context.sf),
|
||||
icon: Icon(Icons.close, color: Colors.white, size: 20 * context.sf),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
)
|
||||
],
|
||||
@@ -48,11 +49,12 @@ class _TeamsPageState extends State<TeamsPage> {
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Divider(color: Colors.grey.withOpacity(0.2)),
|
||||
const Divider(color: Colors.white24),
|
||||
SizedBox(height: 16 * context.sf),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Coluna Temporada
|
||||
Expanded(
|
||||
child: _buildPopupColumn(
|
||||
title: "TEMPORADA",
|
||||
@@ -64,7 +66,8 @@ class _TeamsPageState extends State<TeamsPage> {
|
||||
},
|
||||
),
|
||||
),
|
||||
SizedBox(width: 20 * context.sf),
|
||||
const SizedBox(width: 20),
|
||||
// Coluna Ordenar
|
||||
Expanded(
|
||||
child: _buildPopupColumn(
|
||||
title: "ORDENAR POR",
|
||||
@@ -83,7 +86,7 @@ class _TeamsPageState extends State<TeamsPage> {
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text("CONCLUÍDO", style: TextStyle(color: AppTheme.primaryRed, fontWeight: FontWeight.bold, fontSize: 14 * context.sf)),
|
||||
child: Text("CONCLUÍDO", style: TextStyle(color: const Color(0xFFE74C3C), fontWeight: FontWeight.bold, fontSize: 14 * context.sf)),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -93,24 +96,28 @@ class _TeamsPageState extends State<TeamsPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPopupColumn({required String title, required List<String> options, required String currentValue, required Function(String) onSelect}) {
|
||||
Widget _buildPopupColumn({
|
||||
required String title,
|
||||
required List<String> options,
|
||||
required String currentValue,
|
||||
required Function(String) onSelect,
|
||||
}) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(title, style: TextStyle(color: Colors.grey, fontSize: 11 * context.sf, fontWeight: FontWeight.bold)),
|
||||
SizedBox(height: 12 * context.sf),
|
||||
Text(title, style: const TextStyle(color: Colors.grey, fontSize: 11, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 12),
|
||||
...options.map((opt) {
|
||||
final isSelected = currentValue == opt;
|
||||
return InkWell(
|
||||
onTap: () => onSelect(opt),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 8.0 * context.sf),
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: Text(
|
||||
opt,
|
||||
style: TextStyle(
|
||||
color: isSelected ? AppTheme.primaryRed : Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
|
||||
color: isSelected ? const Color(0xFFE74C3C) : Colors.white70,
|
||||
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
|
||||
fontSize: 14 * context.sf,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -126,11 +133,11 @@ class _TeamsPageState extends State<TeamsPage> {
|
||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
appBar: AppBar(
|
||||
title: Text("Minhas Equipas", style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20 * context.sf)),
|
||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
backgroundColor: const Color(0xFFF5F7FA),
|
||||
elevation: 0,
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.filter_list, color: AppTheme.primaryRed, size: 24 * context.sf),
|
||||
icon: Icon(Icons.filter_list, color: const Color(0xFFE74C3C), size: 24 * context.sf),
|
||||
onPressed: () => _showFilterDialog(context),
|
||||
),
|
||||
],
|
||||
@@ -142,8 +149,8 @@ class _TeamsPageState extends State<TeamsPage> {
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
heroTag: 'add_team_btn',
|
||||
backgroundColor: AppTheme.primaryRed,
|
||||
heroTag: 'add_team_btn', // 👇 A MÁGICA ESTÁ AQUI!
|
||||
backgroundColor: const Color(0xFFE74C3C),
|
||||
child: Icon(Icons.add, color: Colors.white, size: 24 * context.sf),
|
||||
onPressed: () => _showCreateDialog(context),
|
||||
),
|
||||
@@ -152,17 +159,17 @@ class _TeamsPageState extends State<TeamsPage> {
|
||||
|
||||
Widget _buildSearchBar() {
|
||||
return Padding(
|
||||
padding: EdgeInsets.all(16.0 * context.sf),
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: TextField(
|
||||
controller: _searchController,
|
||||
onChanged: (v) => setState(() => _searchQuery = v.toLowerCase()),
|
||||
style: TextStyle(fontSize: 16 * context.sf, color: Theme.of(context).colorScheme.onSurface),
|
||||
style: TextStyle(fontSize: 16 * context.sf),
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Pesquisar equipa...',
|
||||
hintStyle: TextStyle(fontSize: 16 * context.sf, color: Colors.grey),
|
||||
prefixIcon: Icon(Icons.search, color: AppTheme.primaryRed, size: 22 * context.sf),
|
||||
hintStyle: TextStyle(fontSize: 16 * context.sf),
|
||||
prefixIcon: Icon(Icons.search, color: const Color(0xFFE74C3C), size: 22 * context.sf),
|
||||
filled: true,
|
||||
fillColor: Theme.of(context).colorScheme.surface, // 👇 Adapta-se ao Dark Mode
|
||||
fillColor: Colors.white,
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(15 * context.sf), borderSide: BorderSide.none),
|
||||
),
|
||||
),
|
||||
@@ -173,30 +180,51 @@ class _TeamsPageState extends State<TeamsPage> {
|
||||
return StreamBuilder<List<Map<String, dynamic>>>(
|
||||
stream: controller.teamsStream,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) return Center(child: CircularProgressIndicator(color: AppTheme.primaryRed));
|
||||
if (!snapshot.hasData || snapshot.data!.isEmpty) return Center(child: Text("Nenhuma equipa encontrada.", style: TextStyle(fontSize: 16 * context.sf, color: Theme.of(context).colorScheme.onSurface)));
|
||||
if (snapshot.connectionState == ConnectionState.waiting) return const Center(child: CircularProgressIndicator());
|
||||
if (!snapshot.hasData || snapshot.data!.isEmpty) return Center(child: Text("Nenhuma equipa encontrada.", style: TextStyle(fontSize: 16 * context.sf)));
|
||||
|
||||
var data = List<Map<String, dynamic>>.from(snapshot.data!);
|
||||
|
||||
if (_selectedSeason != 'Todas') data = data.where((t) => t['season'] == _selectedSeason).toList();
|
||||
if (_searchQuery.isNotEmpty) data = data.where((t) => t['name'].toString().toLowerCase().contains(_searchQuery)).toList();
|
||||
// --- 1. FILTROS ---
|
||||
if (_selectedSeason != 'Todas') {
|
||||
data = data.where((t) => t['season'] == _selectedSeason).toList();
|
||||
}
|
||||
if (_searchQuery.isNotEmpty) {
|
||||
data = data.where((t) => t['name'].toString().toLowerCase().contains(_searchQuery)).toList();
|
||||
}
|
||||
|
||||
// --- 2. ORDENAÇÃO (FAVORITOS PRIMEIRO) ---
|
||||
data.sort((a, b) {
|
||||
// Apanhar o estado de favorito (tratando null como false)
|
||||
bool favA = a['is_favorite'] ?? false;
|
||||
bool favB = b['is_favorite'] ?? false;
|
||||
if (favA && !favB) return -1;
|
||||
if (!favA && favB) return 1;
|
||||
if (_currentSort == 'Nome') return a['name'].toString().compareTo(b['name'].toString());
|
||||
else return (b['created_at'] ?? '').toString().compareTo((a['created_at'] ?? '').toString());
|
||||
|
||||
// REGRA 1: Favoritos aparecem sempre primeiro
|
||||
if (favA && !favB) return -1; // A sobe
|
||||
if (!favA && favB) return 1; // B sobe
|
||||
|
||||
// REGRA 2: Se o estado de favorito for igual, aplica o filtro do utilizador
|
||||
if (_currentSort == 'Nome') {
|
||||
return a['name'].toString().compareTo(b['name'].toString());
|
||||
} else { // Recentes
|
||||
return (b['created_at'] ?? '').toString().compareTo((a['created_at'] ?? '').toString());
|
||||
}
|
||||
});
|
||||
|
||||
return ListView.builder(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16 * context.sf),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
itemCount: data.length,
|
||||
itemBuilder: (context, index) {
|
||||
final team = Team.fromMap(data[index]);
|
||||
|
||||
// Navegação para estatísticas
|
||||
return GestureDetector(
|
||||
onTap: () => Navigator.push(context, MaterialPageRoute(builder: (context) => TeamStatsPage(team: team))),
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => TeamStatsPage(team: team)),
|
||||
);
|
||||
},
|
||||
child: TeamCard(
|
||||
team: team,
|
||||
controller: controller,
|
||||
@@ -211,7 +239,7 @@ class _TeamsPageState extends State<TeamsPage> {
|
||||
}
|
||||
|
||||
void _showCreateDialog(BuildContext context) {
|
||||
showDialog(context: context, builder: (context) => CreateTeamDialog(sf: context.sf, onConfirm: (name, season, imageUrl) => controller.createTeam(name, season, imageUrl)));
|
||||
showDialog(context: context, builder: (context) => CreateTeamDialog(onConfirm: (name, season, imageUrl) => controller.createTeam(name, season, imageUrl)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,140 +248,73 @@ class TeamCard extends StatelessWidget {
|
||||
final Team team;
|
||||
final TeamController controller;
|
||||
final VoidCallback onFavoriteTap;
|
||||
final double sf;
|
||||
|
||||
const TeamCard({
|
||||
super.key,
|
||||
required this.team,
|
||||
required this.controller,
|
||||
required this.onFavoriteTap,
|
||||
required this.sf,
|
||||
});
|
||||
const TeamCard({super.key, required this.team, required this.controller, required this.onFavoriteTap});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bgColor = Theme.of(context).cardTheme.color ?? Theme.of(context).colorScheme.surface;
|
||||
final textColor = Theme.of(context).colorScheme.onSurface;
|
||||
|
||||
return Container(
|
||||
margin: EdgeInsets.only(bottom: 12 * sf),
|
||||
decoration: BoxDecoration(
|
||||
color: bgColor,
|
||||
borderRadius: BorderRadius.circular(15 * sf),
|
||||
border: Border.all(color: Colors.grey.withOpacity(0.15)),
|
||||
boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.05), blurRadius: 10 * sf)]
|
||||
),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(15 * sf),
|
||||
child: ListTile(
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 16 * sf, vertical: 8 * sf),
|
||||
leading: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 28 * sf,
|
||||
backgroundColor: Colors.grey.withOpacity(0.2),
|
||||
backgroundImage: (team.imageUrl.isNotEmpty && team.imageUrl.startsWith('http'))
|
||||
? NetworkImage(team.imageUrl)
|
||||
: null,
|
||||
child: (team.imageUrl.isEmpty || !team.imageUrl.startsWith('http'))
|
||||
? Text(
|
||||
team.imageUrl.isEmpty ? "🏀" : team.imageUrl,
|
||||
style: TextStyle(fontSize: 24 * sf),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
Positioned(
|
||||
left: -15 * sf,
|
||||
top: -10 * sf,
|
||||
child: IconButton(
|
||||
icon: Icon(
|
||||
team.isFavorite ? Icons.star : Icons.star_border,
|
||||
color: team.isFavorite ? AppTheme.warningAmber : Theme.of(context).colorScheme.onSurface.withOpacity(0.2),
|
||||
size: 28 * sf,
|
||||
shadows: [
|
||||
Shadow(color: Colors.black.withOpacity(team.isFavorite ? 0.3 : 0.1), blurRadius: 4 * sf),
|
||||
],
|
||||
),
|
||||
onPressed: onFavoriteTap,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
title: Text(
|
||||
team.name,
|
||||
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16 * sf, color: textColor),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
subtitle: Padding(
|
||||
padding: EdgeInsets.only(top: 6.0 * sf),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.groups_outlined, size: 16 * sf, color: Colors.grey),
|
||||
SizedBox(width: 4 * sf),
|
||||
StreamBuilder<int>(
|
||||
stream: controller.getPlayerCountStream(team.id),
|
||||
initialData: 0,
|
||||
builder: (context, snapshot) {
|
||||
final count = snapshot.data ?? 0;
|
||||
return Text(
|
||||
"$count Jogs.",
|
||||
style: TextStyle(
|
||||
color: count > 0 ? AppTheme.successGreen : AppTheme.warningAmber, // 👇 Usando cores do tema
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 13 * sf,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
SizedBox(width: 8 * sf),
|
||||
Expanded(
|
||||
child: Text("| ${team.season}", style: TextStyle(color: Colors.grey, fontSize: 13 * sf), overflow: TextOverflow.ellipsis),
|
||||
),
|
||||
],
|
||||
return Card(
|
||||
color: Colors.white, elevation: 3, margin: EdgeInsets.only(bottom: 12 * context.sf),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15 * context.sf)),
|
||||
child: ListTile(
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 16 * context.sf, vertical: 8 * context.sf),
|
||||
leading: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 28 * context.sf, backgroundColor: Colors.grey[200],
|
||||
backgroundImage: (team.imageUrl.isNotEmpty && team.imageUrl.startsWith('http')) ? NetworkImage(team.imageUrl) : null,
|
||||
child: (team.imageUrl.isEmpty || !team.imageUrl.startsWith('http')) ? Text(team.imageUrl.isEmpty ? "🏀" : team.imageUrl, style: TextStyle(fontSize: 24 * context.sf)) : null,
|
||||
),
|
||||
),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
Positioned(
|
||||
left: -15 * context.sf, top: -10 * context.sf,
|
||||
child: IconButton(
|
||||
icon: Icon(team.isFavorite ? Icons.star : Icons.star_border, color: team.isFavorite ? Colors.amber : Colors.black.withOpacity(0.1), size: 28 * context.sf, shadows: [Shadow(color: Colors.black.withOpacity(team.isFavorite ? 0.3 : 0.1), blurRadius: 4 * context.sf)]),
|
||||
onPressed: onFavoriteTap,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
title: Text(team.name, style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16 * context.sf), overflow: TextOverflow.ellipsis),
|
||||
subtitle: Padding(
|
||||
padding: EdgeInsets.only(top: 6.0 * context.sf),
|
||||
child: Row(
|
||||
children: [
|
||||
IconButton(
|
||||
tooltip: 'Ver Estatísticas',
|
||||
icon: Icon(Icons.bar_chart_rounded, color: Colors.blue, size: 24 * sf),
|
||||
onPressed: () => Navigator.push(context, MaterialPageRoute(builder: (context) => TeamStatsPage(team: team))),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: 'Eliminar Equipa',
|
||||
icon: Icon(Icons.delete_outline, color: AppTheme.primaryRed, size: 24 * sf),
|
||||
onPressed: () => _confirmDelete(context, sf, bgColor, textColor),
|
||||
Icon(Icons.groups_outlined, size: 16 * context.sf, color: Colors.grey),
|
||||
SizedBox(width: 4 * context.sf),
|
||||
StreamBuilder<int>(
|
||||
stream: controller.getPlayerCountStream(team.id),
|
||||
initialData: 0,
|
||||
builder: (context, snapshot) {
|
||||
final count = snapshot.data ?? 0;
|
||||
return Text("$count Jogs.", style: TextStyle(color: count > 0 ? Colors.green[700] : Colors.orange, fontWeight: FontWeight.bold, fontSize: 13 * context.sf));
|
||||
},
|
||||
),
|
||||
SizedBox(width: 8 * context.sf),
|
||||
Expanded(child: Text("| ${team.season}", style: TextStyle(color: Colors.grey, fontSize: 13 * context.sf), overflow: TextOverflow.ellipsis)),
|
||||
],
|
||||
),
|
||||
),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
IconButton(tooltip: 'Ver Estatísticas', icon: Icon(Icons.bar_chart_rounded, color: Colors.blue, size: 24 * context.sf), onPressed: () => Navigator.push(context, MaterialPageRoute(builder: (context) => TeamStatsPage(team: team)))),
|
||||
IconButton(tooltip: 'Eliminar Equipa', icon: Icon(Icons.delete_outline, color: const Color(0xFFE74C3C), size: 24 * context.sf), onPressed: () => _confirmDelete(context)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _confirmDelete(BuildContext context, double sf, Color cardColor, Color textColor) {
|
||||
void _confirmDelete(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
backgroundColor: cardColor,
|
||||
surfaceTintColor: Colors.transparent,
|
||||
title: Text('Eliminar Equipa?', style: TextStyle(fontSize: 18 * sf, fontWeight: FontWeight.bold, color: textColor)),
|
||||
content: Text('Tens a certeza que queres eliminar "${team.name}"?', style: TextStyle(fontSize: 14 * sf, color: textColor)),
|
||||
title: Text('Eliminar Equipa?', style: TextStyle(fontSize: 18 * context.sf, fontWeight: FontWeight.bold)),
|
||||
content: Text('Tens a certeza que queres eliminar "${team.name}"?', style: TextStyle(fontSize: 14 * context.sf)),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text('Cancelar', style: TextStyle(fontSize: 14 * sf, color: Colors.grey)),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
controller.deleteTeam(team.id);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: Text('Eliminar', style: TextStyle(color: AppTheme.primaryRed, fontSize: 14 * sf)),
|
||||
),
|
||||
TextButton(onPressed: () => Navigator.pop(context), child: Text('Cancelar', style: TextStyle(fontSize: 14 * context.sf))),
|
||||
TextButton(onPressed: () { controller.deleteTeam(team.id); Navigator.pop(context); }, child: Text('Eliminar', style: TextStyle(color: Colors.red, fontSize: 14 * context.sf))),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -363,9 +324,7 @@ class TeamCard extends StatelessWidget {
|
||||
// --- DIALOG DE CRIAÇÃO ---
|
||||
class CreateTeamDialog extends StatefulWidget {
|
||||
final Function(String name, String season, String imageUrl) onConfirm;
|
||||
final double sf;
|
||||
|
||||
const CreateTeamDialog({super.key, required this.onConfirm, required this.sf});
|
||||
const CreateTeamDialog({super.key, required this.onConfirm});
|
||||
|
||||
@override
|
||||
State<CreateTeamDialog> createState() => _CreateTeamDialogState();
|
||||
@@ -379,33 +338,31 @@ class _CreateTeamDialogState extends State<CreateTeamDialog> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15 * widget.sf)),
|
||||
title: Text('Nova Equipa', style: TextStyle(fontSize: 18 * widget.sf, fontWeight: FontWeight.bold, color: Theme.of(context).colorScheme.onSurface)),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15 * context.sf)),
|
||||
title: Text('Nova Equipa', style: TextStyle(fontSize: 18 * context.sf, fontWeight: FontWeight.bold)),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextField(controller: _nameController, style: TextStyle(fontSize: 14 * widget.sf, color: Theme.of(context).colorScheme.onSurface), decoration: InputDecoration(labelText: 'Nome da Equipa', labelStyle: TextStyle(fontSize: 14 * widget.sf)), textCapitalization: TextCapitalization.words),
|
||||
SizedBox(height: 15 * widget.sf),
|
||||
TextField(controller: _nameController, style: TextStyle(fontSize: 14 * context.sf), decoration: InputDecoration(labelText: 'Nome da Equipa', labelStyle: TextStyle(fontSize: 14 * context.sf)), textCapitalization: TextCapitalization.words),
|
||||
SizedBox(height: 15 * context.sf),
|
||||
DropdownButtonFormField<String>(
|
||||
dropdownColor: Theme.of(context).colorScheme.surface,
|
||||
value: _selectedSeason, decoration: InputDecoration(labelText: 'Temporada', labelStyle: TextStyle(fontSize: 14 * widget.sf)),
|
||||
style: TextStyle(fontSize: 14 * widget.sf, color: Theme.of(context).colorScheme.onSurface),
|
||||
value: _selectedSeason, decoration: InputDecoration(labelText: 'Temporada', labelStyle: TextStyle(fontSize: 14 * context.sf)),
|
||||
style: TextStyle(fontSize: 14 * context.sf, color: Colors.black87),
|
||||
items: ['2023/24', '2024/25', '2025/26'].map((s) => DropdownMenuItem(value: s, child: Text(s))).toList(),
|
||||
onChanged: (val) => setState(() => _selectedSeason = val!),
|
||||
),
|
||||
SizedBox(height: 15 * widget.sf),
|
||||
TextField(controller: _imageController, style: TextStyle(fontSize: 14 * widget.sf, color: Theme.of(context).colorScheme.onSurface), decoration: InputDecoration(labelText: 'URL Imagem ou Emoji', labelStyle: TextStyle(fontSize: 14 * widget.sf), hintText: 'Ex: 🏀 ou https://...', hintStyle: TextStyle(fontSize: 14 * widget.sf, color: Colors.grey))),
|
||||
SizedBox(height: 15 * context.sf),
|
||||
TextField(controller: _imageController, style: TextStyle(fontSize: 14 * context.sf), decoration: InputDecoration(labelText: 'URL Imagem ou Emoji', labelStyle: TextStyle(fontSize: 14 * context.sf), hintText: 'Ex: 🏀 ou https://...', hintStyle: TextStyle(fontSize: 14 * context.sf))),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(context), child: Text('Cancelar', style: TextStyle(fontSize: 14 * widget.sf, color: Colors.grey))),
|
||||
TextButton(onPressed: () => Navigator.pop(context), child: Text('Cancelar', style: TextStyle(fontSize: 14 * context.sf))),
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(backgroundColor: AppTheme.primaryRed, padding: EdgeInsets.symmetric(horizontal: 16 * widget.sf, vertical: 10 * widget.sf)),
|
||||
style: ElevatedButton.styleFrom(backgroundColor: const Color(0xFFE74C3C), padding: EdgeInsets.symmetric(horizontal: 16 * context.sf, vertical: 10 * context.sf)),
|
||||
onPressed: () { if (_nameController.text.trim().isNotEmpty) { widget.onConfirm(_nameController.text.trim(), _selectedSeason, _imageController.text.trim()); Navigator.pop(context); } },
|
||||
child: Text('Criar', style: TextStyle(color: Colors.white, fontSize: 14 * widget.sf)),
|
||||
child: Text('Criar', style: TextStyle(color: Colors.white, fontSize: 14 * context.sf)),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user