fl_chart touch response issue in LineChart

Viewed 1260

I have displayed a Line chart using fl_chart ^0.10.1 (Tested on Flutter ver 52.2.1 & 53.0.1). I am updating the FlSpots from a csv file.

I am trying to get the index or Spot object if I touch somewhere in the plot. But I am getting an empty list from the touchResponse if I touch (both tap or long-press) somewhere.

console

But I am getting the value in the plot itself. I am assuming it's there because of the built-in touch handler. plot

The code I am trying it:

              lineTouchData: LineTouchData(
                          touchCallback: (LineTouchResponse touchResponse) {
                        if (touchResponse.touchInput is FlPanEnd ||
                            touchResponse.touchInput is FlLongPressEnd) {
                          var spots = touchResponse.lineBarSpots;
                          setState(() {
                            var lengthList = spots.length;
                            print(
                                'touched spot---> ${spots.toString()},,,len--->$lengthList');
                          });
                        } else {
                          print('wait');
                        }
                      }),

My end goal is to use and pass the touched index to open a new screen/widget.

1 Answers
Related