We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to change trackball line color dynamically according to theme?

error: "dependOnInheritedWidgetOfExactType<_InheritedTheme>() or dependOnInheritedElement() was called before _HomeScreenState.initState() completed"

void initState(){ _crosshairBehavior = CrosshairBehavior( enable: true, lineColor: Theme.of(context).primaryColor,
                  lineDashArray: <double>[5,5],
                  lineWidth: 2,
                  lineType: CrosshairLineType.vertical

1 Reply

NR Natrayan Ramalingam Syncfusion Team February 14, 2023 01:02 PM UTC

Hi Felipe,

The requirement “How to change crosshair line color dynamically according to the theme” can be achieved by using the crosshairLineColor property which is available in the SfChartThemeData and setting the interactive tooltip as false to hide the tooltip in the primaryYAxis. Please refer to the following code snippet.

body: SfTheme(

    data: SfThemeData(

       chartThemeData: SfChartThemeData(

            crosshairLineColor: Theme.of(context).primaryColor,



    child: SfCartesianChart(

          primaryYAxis: NumericAxis(

               interactiveTooltip: const InteractiveTooltip(enable: false),


          crosshairBehavior: _crosshairBehavior,





We have attached the sample below for your reference. For more details, refer to the ug:





Attachment: f180513_d06109d8.zip

Live Chat Icon For mobile
Up arrow icon