buildChart method

  1. @override
Widget buildChart()
override

Implementation

@override
Widget buildChart() {
  // Apply number formatting
  String formattedValue = numberFormat?.format(value) ?? '$value';

  // Define text styles, potentially based on the provided theme data
  TextStyle labelStyle =
      themeData?.labelStyle ?? const ChartThemeData().labelStyle;
  TextStyle valueStyle = themeData?.valueStyle ??
      const ChartThemeData()
          .valueStyle
          .copyWith(fontSize: 36); // Enlarged for emphasis
  TextStyle unitStyle =
      themeData?.unitStyle ?? const ChartThemeData().unitStyle;

  // Construct the chart widget using the ChartCard for common styling
  return ChartCard(
    themeData: themeData ?? const ChartThemeData(),
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        FittedBox(fit: BoxFit.contain, child: Text(label, style: labelStyle)),
        const Spacer(),
        FittedBox(
            fit: BoxFit.contain,
            child: Text(formattedValue, style: valueStyle)),
        const Spacer(),
        FittedBox(fit: BoxFit.contain, child: Text(unit, style: unitStyle)),
      ],
    ),
  );
}