buildChart method
Implementation
@override
Widget buildChart() {
// Default theme data
const defaultThemeData = ChartThemeData(
backgroundColor: Colors.white,
labelStyle: TextStyle(color: Colors.black, fontSize: 16),
valueStyle: TextStyle(
fontSize: 18, fontWeight: FontWeight.bold, color: Colors.blue),
secondaryValueStyle: TextStyle(
fontSize: 18, fontWeight: FontWeight.bold, color: Colors.green),
unitStyle: TextStyle(color: Colors.grey, fontSize: 14),
);
TextStyle labelStyle = themeData?.labelStyle ?? defaultThemeData.labelStyle;
TextStyle primaryValueStyle =
themeData?.valueStyle ?? defaultThemeData.valueStyle;
TextStyle secondaryValueStyle =
themeData?.secondaryValueStyle ?? defaultThemeData.secondaryValueStyle;
TextStyle unitStyle = themeData?.unitStyle ?? defaultThemeData.unitStyle;
// Apply number formatting
String formattedPrimaryValue = numberFormat?.format(primaryValue) ??
NumberFormat().format(primaryValue);
String formattedSecondaryValue = numberFormat?.format(secondaryValue) ??
NumberFormat().format(secondaryValue);
return ChartCard(
themeData: themeData ?? defaultThemeData,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(label, style: labelStyle),
const Spacer(),
FittedBox(
fit: BoxFit.contain,
child: Text(formattedPrimaryValue, style: primaryValueStyle)),
const Spacer(),
const FittedBox(fit: BoxFit.contain, child: Text('vs')),
const Spacer(),
FittedBox(
fit: BoxFit.contain,
child: Text(formattedSecondaryValue, style: secondaryValueStyle)),
const Spacer(),
Text(unit, style: unitStyle),
],
),
);
}