306 lines
11 KiB
Dart
306 lines
11 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:playmaker/grafico%20de%20pizza/widgets/grafico_widgets.dart'; // Assume que o PieChartWidget está aqui
|
|
import 'dados_grafico.dart';
|
|
import 'controllers/contollers_grafico.dart';
|
|
|
|
class PieChartCard extends StatefulWidget {
|
|
final PieChartController? controller;
|
|
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.title = 'DESEMPENHO',
|
|
this.subtitle = 'Vitórias vs Derrotas',
|
|
this.onTap,
|
|
required this.backgroundColor,
|
|
this.sf = 1.0,
|
|
required this.cardWidth,
|
|
required this.cardHeight,
|
|
});
|
|
|
|
@override
|
|
State<PieChartCard> createState() => _PieChartCardState();
|
|
}
|
|
|
|
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.forward();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_animationController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final data = _controller.chartData;
|
|
final double sf = widget.sf;
|
|
|
|
return AnimatedBuilder(
|
|
animation: _animation,
|
|
builder: (context, child) {
|
|
return Transform.scale(
|
|
scale: 0.95 + (_animation.value * 0.05),
|
|
child: Opacity(
|
|
opacity: _animation.value,
|
|
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: 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
|
|
),
|
|
),
|
|
),
|
|
|
|
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,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
// 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),
|
|
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),
|
|
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),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildDivider(double sf) {
|
|
return Container(
|
|
height: 0.5,
|
|
color: Colors.white.withOpacity(0.1),
|
|
margin: EdgeInsets.symmetric(vertical: 3 * sf),
|
|
);
|
|
}
|
|
} |