toggleSelection property

bool toggleSelection
final

Decides whether to deselect the selected item or not.

Provides an option to decide, whether to deselect the selected data point/series or remain selected, when interacted with it again.

If set to true, deselection will be performed else the point will not get deselected. This works even while calling public methods, in various selection modes, with multi-selection, and also on dynamic changes.

Defaults to true.

late SelectionBehavior selectionBehavior;

void initState() {
  selectionBehavior = SelectionBehavior(
    enable: true,
    toggleSelection: false
  );
  super.initState();
}

Widget build(BuildContext context) {
  return SfCartesianChart(
    series: <BarSeries<SalesData, num>>[
      BarSeries<SalesData, num>(
        selectionBehavior: selectionBehavior
      ),
    ],
  );
}

Implementation

final bool toggleSelection;