buildChart method

  1. @override
Widget buildChart()
override

Implementation

@override
Widget buildChart() {
  // Define default theme data
  const defaultThemeData = ChartThemeData(
    backgroundColor: Colors.white,
    labelStyle: TextStyle(color: Colors.black, fontSize: 16),
    valueStyle: TextStyle(
        fontSize: 24, fontWeight: FontWeight.bold, color: Colors.blue),
    unitStyle: TextStyle(color: Colors.grey, fontSize: 14),
  );

  TextStyle labelStyle = themeData?.labelStyle ?? defaultThemeData.labelStyle;
  TextStyle valueStyle = themeData?.valueStyle ?? defaultThemeData.valueStyle;

  double progressPercent =
      (progress / goal).clamp(0, 1); // Ensure the value is between 0 and 1

  return ChartCard(
    themeData: themeData ?? defaultThemeData,
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        FittedBox(fit: BoxFit.contain, child: Text(label, style: labelStyle)),
        const Spacer(),
        LinearProgressIndicator(
          value: progressPercent,
          backgroundColor: Colors.grey[300],
          valueColor: const AlwaysStoppedAnimation<Color>(Colors.green),
        ),
        const Spacer(),
        FittedBox(
            fit: BoxFit.contain,
            child: Text('${progress.toStringAsFixed(1)}/$goal$unit',
                style: valueStyle)),
      ],
    ),
  );
}