fazer vitoria e derrota

This commit is contained in:
2026-03-10 17:15:10 +00:00
parent d720e09866
commit 49bb371ef4
12 changed files with 940 additions and 742 deletions

View File

@@ -6,32 +6,38 @@ class PieChartWidget extends StatelessWidget {
final double defeatPercentage;
final double drawPercentage;
final double size;
final double sf; // <-- Fator de Escala
const PieChartWidget({
super.key,
required this.victoryPercentage,
required this.defeatPercentage,
this.drawPercentage = 0,
this.size = 140, // Aumentado para 400x300
this.size = 140,
required this.sf, // <-- Obrigatório agora
});
@override
Widget build(BuildContext context) {
// Aplica a escala ao tamanho total do quadrado do gráfico
final double scaledSize = size * sf;
return SizedBox(
width: size,
height: size,
width: scaledSize,
height: scaledSize,
child: CustomPaint(
painter: _PieChartPainter(
victoryPercentage: victoryPercentage,
defeatPercentage: defeatPercentage,
drawPercentage: drawPercentage,
sf: sf, // <-- Passar para desenhar a borda
),
child: _buildCenterLabels(),
child: _buildCenterLabels(scaledSize),
),
);
}
Widget _buildCenterLabels() {
Widget _buildCenterLabels(double scaledSize) {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
@@ -39,16 +45,16 @@ class PieChartWidget extends StatelessWidget {
Text(
'${(victoryPercentage * 100).toStringAsFixed(1)}%',
style: TextStyle(
fontSize: size * 0.2, // Tamanho responsivo (28px para 140px)
fontSize: scaledSize * 0.144, // Mantém-se proporcional
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
SizedBox(height: 4),
SizedBox(height: 4 * sf),
Text(
'Vitórias',
style: TextStyle(
fontSize: size * 0.1, // Tamanho responsivo (14px para 140px)
fontSize: scaledSize * 0.1, // Mantém-se proporcional
color: Colors.white.withOpacity(0.8),
),
),
@@ -62,17 +68,20 @@ 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);
final radius = size.width / 2 - 5;
// Aplica a escala à margem para não cortar a linha da borda num ecrã pequeno
final radius = size.width / 2 - (5 * sf);
// Cores
const victoryColor = Colors.green;
@@ -106,7 +115,7 @@ class _PieChartPainter extends CustomPainter {
final borderPaint = Paint()
..color = borderColor
..style = PaintingStyle.stroke
..strokeWidth = 2;
..strokeWidth = 2 * sf; // <-- Escala na grossura da linha
canvas.drawCircle(center, radius, borderPaint);
}
@@ -130,7 +139,7 @@ class _PieChartPainter extends CustomPainter {
final linePaint = Paint()
..color = Colors.white.withOpacity(0.5)
..style = PaintingStyle.stroke
..strokeWidth = 1.5;
..strokeWidth = 1.5 * sf; // <-- Escala na grossura da linha
final lineX = center.dx + radius * math.cos(startAngle);
final lineY = center.dy + radius * math.sin(startAngle);