Pointers in Fluter Radial Gauge (SfRadialGauge)

23 Apr 20215 minutes to read

Pointer is used to indicate values on an axis. The radial gauge control has three types of pointers:

Marker pointer
Needle pointer
Range pointer
[Widget pointer]

All the pointers can be customized as needed. You can add multiple pointers to the gauge to point multiple values on the same scale. The value of the pointer is set using the value property.

multiple pointers

Multiple pointers

In addition to the default pointer, you can add n number of pointers to an axis by adding in the pointers property.

  • dart
  • @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: Center(
                  child: SfRadialGauge(
                    axes: <RadialAxis>[RadialAxis(
                      pointers: <GaugePointer>[RangePointer(value: 30, ), 
                       MarkerPointer(value: 70),
                      NeedlePointer(value: 60)]
                    )],
                  )
                ),
              );
            }

    multiple pointers

    Pointer Dragging

    Pointers can be dragged over the scale value. It can be achieved by clicking and dragging the pointer. To enable or disable the pointer drag, use the enableDragging property.

  • dart
  • @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: Center(
                  child: SfRadialGauge(
                    axes: <RadialAxis>[RadialAxis( 
                     axisLineStyle: AxisLineStyle(thickness: 30, color: Colors.lightBlueAccent), 
                     showTicks: false,
                     pointers: <GaugePointer>[
                       MarkerPointer(value: 30, enableDragging: true, 
                       markerWidth: 30, markerHeight: 30, markerOffset: -15,
                       color: Colors.indigo)
                     ]
                    )],
                  )
                ),
              );
            }

    pointer dragging

    Event

    onValueChangeStart - Occurs whenever the pointer starts to drag.

    onValueChanging - Occurs before the current drag value gets updated as pointer value. The cancel argument of ValueChangingArgs allows to restrict the update of current drag value as pointer value.

    onValueChanged - Occurs whenever the pointer value is changed while dragging.

    onValueChangeEnd - Occurs once the dragging of the pointer gets completed.

  • dart
  • @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: Center(
                  child: SfRadialGauge(
                    axes: <RadialAxis>[RadialAxis(
                      pointers: <GaugePointer>[ RangePointer(value: 30, 
                      enableDragging: true,
                      onValueChanging: onValueChanging,
                      onValueChanged: onvalueChanged)]
                    )],
                  )
                ),
              );
            }
    
    void onValueChanging(ValueChangingArgs args){
      if(args.value > 60){
          args.cancel = true;
      }
    }
    
    void onvalueChanged(double value){
    
    }