vai te lixar github

This commit is contained in:
2026-03-16 22:09:01 +00:00
parent 1917b5fe10
commit cf0a9a9890
22 changed files with 1929 additions and 1290 deletions

View File

@@ -19,12 +19,9 @@ class PieChartWidget extends StatelessWidget {
Widget build(BuildContext context) {
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(
@@ -32,7 +29,7 @@ class PieChartWidget extends StatelessWidget {
width: size,
height: size,
child: CustomPaint(
painter: _PieChartPainter(
painter: _DonutChartPainter(
victoryPercentage: victoryPercentage,
defeatPercentage: defeatPercentage,
drawPercentage: drawPercentage,
@@ -48,24 +45,27 @@ class PieChartWidget extends StatelessWidget {
}
Widget _buildCenterLabels(double size) {
final bool hasGames = victoryPercentage > 0 || defeatPercentage > 0 || drawPercentage > 0;
return Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'${(victoryPercentage * 100).toStringAsFixed(1)}%',
// 👇 Casa decimal aplicada aqui!
hasGames ? '${(victoryPercentage * 100).toStringAsFixed(1)}%' : '---',
style: TextStyle(
fontSize: size * 0.18, // O texto cresce ou encolhe com o círculo
fontSize: size * (hasGames ? 0.20 : 0.15),
fontWeight: FontWeight.bold,
color: Colors.white,
color: hasGames ? Colors.white : Colors.white54,
),
),
SizedBox(height: size * 0.02),
Text(
'Vitórias',
hasGames ? 'Vitórias' : 'Sem Jogos',
style: TextStyle(
fontSize: size * 0.10,
color: Colors.white.withOpacity(0.8),
fontSize: size * 0.08,
color: hasGames ? Colors.white70 : Colors.white38,
),
),
],
@@ -73,12 +73,12 @@ class PieChartWidget extends StatelessWidget {
}
}
class _PieChartPainter extends CustomPainter {
class _DonutChartPainter extends CustomPainter {
final double victoryPercentage;
final double defeatPercentage;
final double drawPercentage;
_PieChartPainter({
_DonutChartPainter({
required this.victoryPercentage,
required this.defeatPercentage,
required this.drawPercentage,
@@ -87,59 +87,40 @@ class _PieChartPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final center = Offset(size.width / 2, size.height / 2);
// Margem de 5% para a linha de fora não ser cortada
final radius = (size.width / 2) - (size.width * 0.05);
final radius = (size.width / 2) - (size.width * 0.1);
final strokeWidth = size.width * 0.2;
if (victoryPercentage == 0 && defeatPercentage == 0 && drawPercentage == 0) {
final bgPaint = Paint()
..color = Colors.white.withOpacity(0.05)
..style = PaintingStyle.stroke
..strokeWidth = strokeWidth;
canvas.drawCircle(center, radius, bgPaint);
return;
}
const victoryColor = Colors.green;
const defeatColor = Colors.red;
const drawColor = Colors.yellow;
const borderColor = Colors.white30;
const drawColor = Colors.amber;
double startAngle = -math.pi / 2;
if (victoryPercentage > 0) {
final sweepAngle = 2 * math.pi * victoryPercentage;
_drawSector(canvas, center, radius, startAngle, sweepAngle, victoryColor, size.width);
startAngle += sweepAngle;
}
if (drawPercentage > 0) {
final sweepAngle = 2 * math.pi * drawPercentage;
_drawSector(canvas, center, radius, startAngle, sweepAngle, drawColor, size.width);
startAngle += sweepAngle;
}
if (defeatPercentage > 0) {
final sweepAngle = 2 * math.pi * defeatPercentage;
_drawSector(canvas, center, radius, startAngle, sweepAngle, defeatColor, size.width);
}
final borderPaint = Paint()
..color = borderColor
..style = PaintingStyle.stroke
..strokeWidth = size.width * 0.02;
canvas.drawCircle(center, radius, borderPaint);
}
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);
if (sweepAngle < 2 * math.pi) {
final linePaint = Paint()
..color = Colors.white.withOpacity(0.5)
void drawDonutSector(double percentage, Color color) {
if (percentage <= 0) return;
final sweepAngle = 2 * math.pi * percentage;
final paint = Paint()
..color = color
..style = PaintingStyle.stroke
..strokeWidth = totalWidth * 0.015;
..strokeWidth = strokeWidth
..strokeCap = StrokeCap.butt;
final lineX = center.dx + radius * math.cos(startAngle);
final lineY = center.dy + radius * math.sin(startAngle);
canvas.drawLine(center, Offset(lineX, lineY), linePaint);
canvas.drawArc(Rect.fromCircle(center: center, radius: radius), startAngle, sweepAngle, false, paint);
startAngle += sweepAngle;
}
drawDonutSector(victoryPercentage, victoryColor);
drawDonutSector(drawPercentage, drawColor);
drawDonutSector(defeatPercentage, defeatColor);
}
@override