historico de jogos
This commit is contained in:
@@ -1,29 +1,21 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:playmaker/grafico%20de%20pizza/dados_grafico.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../dados_grafico.dart'; // Ajusta o caminho se der erro de import
|
||||
|
||||
class PieChartController extends ChangeNotifier {
|
||||
PieChartData _chartData = PieChartData(victories: 25, defeats: 10);
|
||||
|
||||
PieChartData get chartData => _chartData;
|
||||
|
||||
void updateData({int? victories, int? defeats, int? draws}) {
|
||||
_chartData = PieChartData(
|
||||
victories: victories ?? _chartData.victories,
|
||||
defeats: defeats ?? _chartData.defeats,
|
||||
draws: draws ?? _chartData.draws,
|
||||
);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void incrementVictories() {
|
||||
updateData(victories: _chartData.victories + 1);
|
||||
}
|
||||
|
||||
void incrementDefeats() {
|
||||
updateData(defeats: _chartData.defeats + 1);
|
||||
}
|
||||
|
||||
void reset() {
|
||||
updateData(victories: 0, defeats: 0, draws: 0);
|
||||
}
|
||||
}
|
||||
class PieChartController extends ChangeNotifier {
|
||||
PieChartData _chartData = const PieChartData(victories: 0, defeats: 0, draws: 0);
|
||||
|
||||
PieChartData get chartData => _chartData;
|
||||
|
||||
void updateData({int? victories, int? defeats, int? draws}) {
|
||||
_chartData = PieChartData(
|
||||
victories: victories ?? _chartData.victories,
|
||||
defeats: defeats ?? _chartData.defeats,
|
||||
draws: draws ?? _chartData.draws, // 👇 AGORA ELE ACEITA OS EMPATES
|
||||
);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void reset() {
|
||||
updateData(victories: 0, defeats: 0, draws: 0);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
class PieChartData {
|
||||
final int victories;
|
||||
final int defeats;
|
||||
final int draws;
|
||||
final int draws; // 👇 AQUI ESTÃO OS EMPATES
|
||||
|
||||
const PieChartData({
|
||||
required this.victories,
|
||||
@@ -9,6 +9,7 @@ class PieChartData {
|
||||
this.draws = 0,
|
||||
});
|
||||
|
||||
// 👇 MATEMÁTICA ATUALIZADA 👇
|
||||
int get total => victories + defeats + draws;
|
||||
|
||||
double get victoryPercentage => total > 0 ? victories / total : 0;
|
||||
@@ -22,5 +23,6 @@ class PieChartData {
|
||||
'total': total,
|
||||
'victoryPercentage': victoryPercentage,
|
||||
'defeatPercentage': defeatPercentage,
|
||||
'drawPercentage': drawPercentage,
|
||||
};
|
||||
}
|
||||
@@ -1,30 +1,27 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:playmaker/grafico%20de%20pizza/widgets/grafico_widgets.dart'; // Assume que o PieChartWidget está aqui
|
||||
import 'package:playmaker/grafico%20de%20pizza/widgets/grafico_widgets.dart';
|
||||
import 'dados_grafico.dart';
|
||||
import 'controllers/contollers_grafico.dart';
|
||||
|
||||
class PieChartCard extends StatefulWidget {
|
||||
final PieChartController? controller;
|
||||
final int victories;
|
||||
final int defeats;
|
||||
final int draws;
|
||||
final String title;
|
||||
final String subtitle;
|
||||
final Color backgroundColor;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
// Variáveis de escala e tamanho
|
||||
final double sf;
|
||||
final double cardWidth;
|
||||
final double cardHeight;
|
||||
|
||||
const PieChartCard({
|
||||
super.key,
|
||||
this.controller,
|
||||
this.victories = 0,
|
||||
this.defeats = 0,
|
||||
this.draws = 0,
|
||||
this.title = 'DESEMPENHO',
|
||||
this.subtitle = 'Vitórias vs Derrotas',
|
||||
this.subtitle = 'Temporada',
|
||||
this.onTap,
|
||||
required this.backgroundColor,
|
||||
this.sf = 1.0,
|
||||
required this.cardWidth,
|
||||
required this.cardHeight,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -32,30 +29,26 @@ class PieChartCard extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _PieChartCardState extends State<PieChartCard> with SingleTickerProviderStateMixin {
|
||||
late PieChartController _controller;
|
||||
late AnimationController _animationController;
|
||||
late Animation<double> _animation;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = widget.controller ?? PieChartController();
|
||||
|
||||
_animationController = AnimationController(
|
||||
duration: const Duration(milliseconds: 600),
|
||||
vsync: this,
|
||||
);
|
||||
|
||||
_animation = Tween<double>(begin: 0.0, end: 1.0).animate(
|
||||
CurvedAnimation(
|
||||
parent: _animationController,
|
||||
curve: Curves.easeOutBack,
|
||||
),
|
||||
);
|
||||
|
||||
_animationController = AnimationController(duration: const Duration(milliseconds: 600), vsync: this);
|
||||
_animation = Tween<double>(begin: 0.0, end: 1.0).animate(CurvedAnimation(parent: _animationController, curve: Curves.easeOutBack));
|
||||
_animationController.forward();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(PieChartCard oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.victories != widget.victories || oldWidget.defeats != widget.defeats || oldWidget.draws != widget.draws) {
|
||||
_animationController.reset();
|
||||
_animationController.forward();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_animationController.dispose();
|
||||
@@ -64,243 +57,160 @@ class _PieChartCardState extends State<PieChartCard> with SingleTickerProviderSt
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final data = _controller.chartData;
|
||||
final double sf = widget.sf;
|
||||
final data = PieChartData(victories: widget.victories, defeats: widget.defeats, draws: widget.draws);
|
||||
|
||||
return AnimatedBuilder(
|
||||
return AnimatedBuilder(
|
||||
animation: _animation,
|
||||
builder: (context, child) {
|
||||
return Transform.scale(
|
||||
scale: 0.95 + (_animation.value * 0.05),
|
||||
// O scale pode passar de 1.0 (efeito back), mas a opacidade NÃO
|
||||
scale: 0.95 + (_animation.value * 0.05),
|
||||
child: Opacity(
|
||||
opacity: _animation.value,
|
||||
// 👇 AQUI ESTÁ A FIX: Garante que fica entre 0 e 1
|
||||
opacity: _animation.value.clamp(0.0, 1.0),
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: SizedBox( // <-- Força a largura e altura exatas passadas pelo HomeScreen
|
||||
width: widget.cardWidth,
|
||||
height: widget.cardHeight,
|
||||
child: Card(
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(20 * sf),
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: widget.onTap,
|
||||
borderRadius: BorderRadius.circular(20 * sf),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20 * sf),
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
widget.backgroundColor.withOpacity(0.9),
|
||||
widget.backgroundColor.withOpacity(0.7),
|
||||
],
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(16.0 * sf),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Cabeçalho compacto
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
widget.title,
|
||||
style: TextStyle(
|
||||
fontSize: 12 * sf,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white.withOpacity(0.9),
|
||||
letterSpacing: 1.5,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 2 * sf),
|
||||
Text(
|
||||
widget.subtitle,
|
||||
style: TextStyle(
|
||||
fontSize: 14 * sf,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: EdgeInsets.all(6 * sf),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.orange.withOpacity(0.8),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(
|
||||
Icons.pie_chart,
|
||||
size: 16 * sf,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
SizedBox(height: 8 * sf),
|
||||
|
||||
// Conteúdo principal
|
||||
Expanded(
|
||||
child: Row(
|
||||
children: [
|
||||
// Gráfico de pizza
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Center(
|
||||
child: Card(
|
||||
margin: EdgeInsets.zero,
|
||||
elevation: 4,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)),
|
||||
child: InkWell(
|
||||
onTap: widget.onTap,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
gradient: LinearGradient(begin: Alignment.topLeft, end: Alignment.bottomRight, colors: [widget.backgroundColor.withOpacity(0.9), widget.backgroundColor.withOpacity(0.7)]),
|
||||
),
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final double ch = constraints.maxHeight;
|
||||
final double cw = constraints.maxWidth;
|
||||
|
||||
return Padding(
|
||||
padding: EdgeInsets.all(cw * 0.06),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 👇 TÍTULOS UM POUCO MAIS PRESENTES
|
||||
FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Text(widget.title.toUpperCase(), style: TextStyle(fontSize: ch * 0.06, fontWeight: FontWeight.bold, color: Colors.white.withOpacity(0.9), letterSpacing: 1.0)),
|
||||
),
|
||||
FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Text(widget.subtitle, style: TextStyle(fontSize: ch * 0.07, fontWeight: FontWeight.bold, color: Colors.white)),
|
||||
),
|
||||
|
||||
SizedBox(height: ch * 0.03),
|
||||
|
||||
// MEIO (GRÁFICO + ESTATÍSTICAS)
|
||||
Expanded(
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: PieChartWidget(
|
||||
victoryPercentage: data.victoryPercentage,
|
||||
defeatPercentage: data.defeatPercentage,
|
||||
drawPercentage: data.drawPercentage,
|
||||
size: 120, // O PieChartWidget vai multiplicar isto por `sf` internamente
|
||||
sf: sf, // <-- Passa a escala para o gráfico
|
||||
sf: widget.sf,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(width: 8 * sf),
|
||||
|
||||
// Estatísticas ultra compactas e sem overflows
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildMiniStatRow("VIT", data.victories.toString(), (data.victoryPercentage * 100).toStringAsFixed(0), Colors.green, sf),
|
||||
_buildDivider(sf),
|
||||
_buildMiniStatRow("DER", data.defeats.toString(), (data.defeatPercentage * 100).toStringAsFixed(0), Colors.red, sf),
|
||||
_buildDivider(sf),
|
||||
_buildMiniStatRow("TOT", data.total.toString(), "100", Colors.white, sf),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(height: 10 * sf),
|
||||
|
||||
// Win rate - Com FittedBox para não estoirar
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 8 * sf, vertical: 6 * sf),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12 * sf),
|
||||
),
|
||||
child: FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
data.victoryPercentage > 0.5
|
||||
? Icons.trending_up
|
||||
: Icons.trending_down,
|
||||
color: data.victoryPercentage > 0.5
|
||||
? Colors.green
|
||||
: Colors.red,
|
||||
size: 16 * sf,
|
||||
),
|
||||
SizedBox(width: 6 * sf),
|
||||
Text(
|
||||
'Win Rate: ${(data.victoryPercentage * 100).toStringAsFixed(1)}%',
|
||||
style: TextStyle(
|
||||
fontSize: 12 * sf,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
SizedBox(width: cw * 0.05),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildDynStatRow("VIT", data.victories.toString(), (data.victoryPercentage * 100).toStringAsFixed(0), Colors.green, ch),
|
||||
_buildDynStatRow("EMP", data.draws.toString(), (data.drawPercentage * 100).toStringAsFixed(0), Colors.yellow, ch),
|
||||
_buildDynStatRow("DER", data.defeats.toString(), (data.defeatPercentage * 100).toStringAsFixed(0), Colors.red, ch),
|
||||
_buildDynDivider(ch),
|
||||
_buildDynStatRow("TOT", data.total.toString(), "100", Colors.white, ch),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// 👇 RODAPÉ AJUSTADO
|
||||
SizedBox(height: ch * 0.03),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: EdgeInsets.symmetric(vertical: ch * 0.035),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white24, // Igual ao fundo do botão detalhes
|
||||
borderRadius: BorderRadius.circular(ch * 0.03), // Borda arredondada
|
||||
),
|
||||
child: Center(
|
||||
child: FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
data.victoryPercentage >= 0.5 ? Icons.trending_up : Icons.trending_down,
|
||||
color: Colors.green,
|
||||
size: ch * 0.09
|
||||
),
|
||||
SizedBox(width: cw * 0.02),
|
||||
Text(
|
||||
'WIN RATE: ${(data.victoryPercentage * 100).toStringAsFixed(1)}%',
|
||||
style: TextStyle(
|
||||
fontSize: ch * 0.05,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Função auxiliar BLINDADA contra overflows
|
||||
Widget _buildMiniStatRow(String label, String number, String percent, Color color, double sf) {
|
||||
return Container(
|
||||
margin: EdgeInsets.only(bottom: 4 * sf),
|
||||
// 👇 PERCENTAGENS SUBIDAS LIGEIRAMENTE (0.10 e 0.045)
|
||||
Widget _buildDynStatRow(String label, String number, String percent, Color color, double ch) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(bottom: ch * 0.01),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 28 * sf,
|
||||
child: FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
number,
|
||||
style: TextStyle(fontSize: 22 * sf, fontWeight: FontWeight.bold, color: color, height: 1.0),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 4 * sf),
|
||||
// Número subiu para 0.10
|
||||
Expanded(flex: 2, child: FittedBox(fit: BoxFit.scaleDown, alignment: Alignment.centerLeft, child: Text(number, style: TextStyle(fontSize: ch * 0.10, fontWeight: FontWeight.bold, color: color, height: 1.0)))),
|
||||
SizedBox(width: ch * 0.02),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 6 * sf,
|
||||
height: 6 * sf,
|
||||
margin: EdgeInsets.only(right: 3 * sf),
|
||||
decoration: BoxDecoration(color: color, shape: BoxShape.circle),
|
||||
),
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(fontSize: 9 * sf, color: Colors.white.withOpacity(0.8), fontWeight: FontWeight.w600),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Text(
|
||||
'$percent%',
|
||||
style: TextStyle(fontSize: 10 * sf, color: color, fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
flex: 3,
|
||||
child: Column(crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [
|
||||
Row(children: [
|
||||
Container(width: ch * 0.018, height: ch * 0.018, margin: EdgeInsets.only(right: ch * 0.015), decoration: BoxDecoration(color: color, shape: BoxShape.circle)),
|
||||
// Label subiu para 0.045
|
||||
Expanded(child: FittedBox(fit: BoxFit.scaleDown, alignment: Alignment.centerLeft, child: Text(label, style: TextStyle(fontSize: ch * 0.033, color: Colors.white.withOpacity(0.8), fontWeight: FontWeight.w600))))
|
||||
]),
|
||||
// Percentagem subiu para 0.05
|
||||
FittedBox(fit: BoxFit.scaleDown, alignment: Alignment.centerLeft, child: Text('$percent%', style: TextStyle(fontSize: ch * 0.04, color: color, fontWeight: FontWeight.bold))),
|
||||
]),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDivider(double sf) {
|
||||
return Container(
|
||||
height: 0.5,
|
||||
color: Colors.white.withOpacity(0.1),
|
||||
margin: EdgeInsets.symmetric(vertical: 3 * sf),
|
||||
);
|
||||
Widget _buildDynDivider(double ch) {
|
||||
return Container(height: 0.5, color: Colors.white.withOpacity(0.1), margin: EdgeInsets.symmetric(vertical: ch * 0.01));
|
||||
}
|
||||
}
|
||||
@@ -5,61 +5,70 @@ class PieChartWidget extends StatelessWidget {
|
||||
final double victoryPercentage;
|
||||
final double defeatPercentage;
|
||||
final double drawPercentage;
|
||||
final double size;
|
||||
final double sf; // <-- Fator de Escala
|
||||
final double sf;
|
||||
|
||||
const PieChartWidget({
|
||||
super.key,
|
||||
required this.victoryPercentage,
|
||||
required this.defeatPercentage,
|
||||
this.drawPercentage = 0,
|
||||
this.size = 140,
|
||||
required this.sf, // <-- Obrigatório agora
|
||||
required this.sf,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Aplica a escala ao tamanho total do quadrado do gráfico
|
||||
final double scaledSize = size * sf;
|
||||
|
||||
return SizedBox(
|
||||
width: scaledSize,
|
||||
height: scaledSize,
|
||||
child: CustomPaint(
|
||||
painter: _PieChartPainter(
|
||||
victoryPercentage: victoryPercentage,
|
||||
defeatPercentage: defeatPercentage,
|
||||
drawPercentage: drawPercentage,
|
||||
sf: sf, // <-- Passar para desenhar a borda
|
||||
),
|
||||
child: _buildCenterLabels(scaledSize),
|
||||
),
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
// 👇 MAGIA ANTI-DESAPARECIMENTO 👇
|
||||
// Vê o espaço real. Se por algum motivo for infinito, assume 100 para não sumir.
|
||||
final double w = constraints.maxWidth.isInfinite ? 100.0 : constraints.maxWidth;
|
||||
final double h = constraints.maxHeight.isInfinite ? 100.0 : constraints.maxHeight;
|
||||
|
||||
// Pega no menor valor para garantir que o círculo não é cortado
|
||||
final double size = math.min(w, h);
|
||||
|
||||
return Center(
|
||||
child: SizedBox(
|
||||
width: size,
|
||||
height: size,
|
||||
child: CustomPaint(
|
||||
painter: _PieChartPainter(
|
||||
victoryPercentage: victoryPercentage,
|
||||
defeatPercentage: defeatPercentage,
|
||||
drawPercentage: drawPercentage,
|
||||
),
|
||||
child: Center(
|
||||
child: _buildCenterLabels(size),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCenterLabels(double scaledSize) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
'${(victoryPercentage * 100).toStringAsFixed(1)}%',
|
||||
style: TextStyle(
|
||||
fontSize: scaledSize * 0.144, // Mantém-se proporcional
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
Widget _buildCenterLabels(double size) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'${(victoryPercentage * 100).toStringAsFixed(1)}%',
|
||||
style: TextStyle(
|
||||
fontSize: size * 0.18, // O texto cresce ou encolhe com o círculo
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
SizedBox(height: 4 * sf),
|
||||
Text(
|
||||
'Vitórias',
|
||||
style: TextStyle(
|
||||
fontSize: scaledSize * 0.1, // Mantém-se proporcional
|
||||
color: Colors.white.withOpacity(0.8),
|
||||
),
|
||||
),
|
||||
SizedBox(height: size * 0.02),
|
||||
Text(
|
||||
'Vitórias',
|
||||
style: TextStyle(
|
||||
fontSize: size * 0.10,
|
||||
color: Colors.white.withOpacity(0.8),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -68,78 +77,63 @@ class _PieChartPainter extends CustomPainter {
|
||||
final double victoryPercentage;
|
||||
final double defeatPercentage;
|
||||
final double drawPercentage;
|
||||
final double sf; // <-- Escala no pintor
|
||||
|
||||
_PieChartPainter({
|
||||
required this.victoryPercentage,
|
||||
required this.defeatPercentage,
|
||||
required this.drawPercentage,
|
||||
required this.sf,
|
||||
});
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final center = Offset(size.width / 2, size.height / 2);
|
||||
// Aplica a escala à margem para não cortar a linha da borda num ecrã pequeno
|
||||
final radius = size.width / 2 - (5 * sf);
|
||||
// Margem de 5% para a linha de fora não ser cortada
|
||||
final radius = (size.width / 2) - (size.width * 0.05);
|
||||
|
||||
// Cores
|
||||
const victoryColor = Colors.green;
|
||||
const defeatColor = Colors.red;
|
||||
const drawColor = Colors.yellow;
|
||||
const borderColor = Colors.white30;
|
||||
|
||||
double startAngle = 0;
|
||||
double startAngle = -math.pi / 2;
|
||||
|
||||
// Vitórias (verde)
|
||||
if (victoryPercentage > 0) {
|
||||
final sweepAngle = 2 * math.pi * victoryPercentage;
|
||||
_drawSector(canvas, center, radius, startAngle, sweepAngle, victoryColor);
|
||||
_drawSector(canvas, center, radius, startAngle, sweepAngle, victoryColor, size.width);
|
||||
startAngle += sweepAngle;
|
||||
}
|
||||
|
||||
// Empates (amarelo)
|
||||
if (drawPercentage > 0) {
|
||||
final sweepAngle = 2 * math.pi * drawPercentage;
|
||||
_drawSector(canvas, center, radius, startAngle, sweepAngle, drawColor);
|
||||
_drawSector(canvas, center, radius, startAngle, sweepAngle, drawColor, size.width);
|
||||
startAngle += sweepAngle;
|
||||
}
|
||||
|
||||
// Derrotas (vermelho)
|
||||
if (defeatPercentage > 0) {
|
||||
final sweepAngle = 2 * math.pi * defeatPercentage;
|
||||
_drawSector(canvas, center, radius, startAngle, sweepAngle, defeatColor);
|
||||
_drawSector(canvas, center, radius, startAngle, sweepAngle, defeatColor, size.width);
|
||||
}
|
||||
|
||||
// Borda
|
||||
final borderPaint = Paint()
|
||||
..color = borderColor
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 2 * sf; // <-- Escala na grossura da linha
|
||||
..strokeWidth = size.width * 0.02;
|
||||
|
||||
canvas.drawCircle(center, radius, borderPaint);
|
||||
}
|
||||
|
||||
void _drawSector(Canvas canvas, Offset center, double radius,
|
||||
double startAngle, double sweepAngle, Color color) {
|
||||
void _drawSector(Canvas canvas, Offset center, double radius, double startAngle, double sweepAngle, Color color, double totalWidth) {
|
||||
final paint = Paint()
|
||||
..color = color
|
||||
..style = PaintingStyle.fill;
|
||||
|
||||
canvas.drawArc(
|
||||
Rect.fromCircle(center: center, radius: radius),
|
||||
startAngle,
|
||||
sweepAngle,
|
||||
true,
|
||||
paint,
|
||||
);
|
||||
canvas.drawArc(Rect.fromCircle(center: center, radius: radius), startAngle, sweepAngle, true, paint);
|
||||
|
||||
// Linha divisória
|
||||
if (sweepAngle < 2 * math.pi) {
|
||||
final linePaint = Paint()
|
||||
..color = Colors.white.withOpacity(0.5)
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 1.5 * sf; // <-- Escala na grossura da linha
|
||||
..strokeWidth = totalWidth * 0.015;
|
||||
|
||||
final lineX = center.dx + radius * math.cos(startAngle);
|
||||
final lineY = center.dy + radius * math.sin(startAngle);
|
||||
|
||||
Reference in New Issue
Block a user