下面这段代码是fl_chart自定义x,y坐标的文本,在setState的时候会很卡,解决方案改回插件默认,只修改文本颜色和字体
Widget bottomTitleWidgets(double value, TitleMeta meta) {
const style = TextStyle(
color: Color(0xff999999),
fontWeight: FontWeight.w400,
fontSize: 12,
);
Widget text;
final minX = (_getNumberX()) ~/ 8;
if (value.toInt() == 0) {
text = const Text('0', style: style);
} else if (value.toInt() == minX) {
text = Text(minX.toString(), style: style);
} else if (value.toInt() == minX * 2) {
text = Text((minX * 2).toString(), style: style);
} else if (value.toInt() == minX * 3) {
text = Text((minX * 3).toString(), style: style);
} else if (value.toInt() == minX * 4) {
text = Text((minX * 4).toString(), style: style);
} else if (value.toInt() == minX * 5) {
text = Text((minX * 5).toString(), style: style);
} else if (value.toInt() == minX * 6) {
text = Text((minX * 6).toString(), style: style);
} else if (value.toInt() == minX * 7) {
text = Text((minX * 7).toString(), style: style);
} else {
text = const Text('', style: style);
}
return SideTitleWidget(
axisSide: meta.axisSide,
space: 10,
child: text,
);
}
修改后
Widget bottomTitleWidgets(double value, TitleMeta meta) {
return SideTitleWidget(
axisSide: meta.axisSide,
child: Text(
meta.formattedValue,
style: const TextStyle(
color: Color(0xff999999),
fontWeight: FontWeight.w400,
fontSize: 12,
),
),
);
}