【问题标题】:fl_chart error the getter 'touchinput' isn't defined for the type 'FlTouchEvent'fl_chart 错误 getter \'touchinput\' 没有为类型 \'FlTouchEvent\' 定义
【发布时间】:2022-12-19 16:44:49
【问题描述】:

在使用 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;
                        }
                      });
                    },
                  ),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}

我怎样才能解决这个错误?

【问题讨论】:

    标签: flutter dart fl-chart


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-22
      • 2021-08-11
      • 2021-02-11
      • 2019-12-01
      • 2022-06-17
      • 2023-01-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多