dart fl_chart错误:没有为类型“FlTouchEvent”定义获取器“touchinput”

chhkpiq4  于 2022-12-20  发布在  其他
关注(0)|答案(1)|浏览(201)

当我在flutter应用程序上实现fl_chart包中的饼图时,我尝试运行该程序时收到以下错误:
没有为类型“FlTouchEvent”定义getter“touchinput”。请尝试导入定义“touchInput”的库,将名称更正为现有getter的名称,或者定义名为“touchInput”〈的getter或字段

实现的代码段

class _ActivityPieChartState extends State<ActivityPieChart> {
  int _touchIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Container(
      height: SizeConfig.blockSizeHorizontal * 25,
      child: Card(
        color: Colors.black,
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(18)),
        child: Row(
          children: [
            Container(
              width: SizeConfig.blockSizeHorizontal * 60,
              child: PieChart(
                PieChartData(
                  borderData: FlBorderData(show: false),
                  //This is to make chart interactive when user touches areas of the chart
                  pieTouchData: PieTouchData(
                    touchCallback: (pieTouchResponse) {
                      setState(() {
                        if (pieTouchResponse.touchedSection is FlLongPressEnd ||
                            pieTouchResponse.touchedSection is FlPanEndEvent) {
                          _touchIndex = -1;
                        } else {
                          _touchIndex = pieTouchResponse.touchedSectionIndex;
                        }
                      });
                    },
                  ),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}

我如何能够修复这个错误?

4ioopgfo

4ioopgfo1#

这里toughCallback函数有两个参数(FlTouchEvent、PieTouchResponse),因为您没有使用FlTouchEvent,所以可以给予下划线作为第一个参数(_)。

相关问题