How to create a circular progress bar using the Flutter radial gauge (SfRadialGauge)
Description
This article describes how to create a circular progress bar using the Flutter radial gauge widget.
Solution
You can achieve a circular progress bar by using the range pointer and annotation features of radial gauge widget.
Step 1: Create a radial gauge widget and add a radial axis into it.
@override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, body: Center( child: SfRadialGauge( axes: <RadialAxis>[RadialAxis()], ), ), ); }
Step 2: Set the startAngle and endAngle as 270 to get a full circular scale and customize the axis look as required for progress bar.
axes: <RadialAxis>[ RadialAxis( showLabels: false, showTicks: false, startAngle: 270, endAngle: 270, minimum: 0, maximum: 100, radiusFactor: 0.85, axisLineStyle: AxisLineStyle( color: Color.fromRGBO(106, 110, 246, 0.2), thicknessUnit: GaugeSizeUnit.factor, thickness: 0.1), ), ],
Step 3: Add the RangePointer and set the value to annotate the progress in the radial scale.
pointers: <GaugePointer>[ RangePointer( value: _pointerValue, cornerStyle: CornerStyle.bothCurve, enableAnimation: true, animationDuration: 1200, animationType: AnimationType.ease, sizeUnit: GaugeSizeUnit.factor, color: const Color(0xFF6A6EF6), width: 0.1), ]
Step 4: Add a Text widget as GaugeAnnotation to display the current progress value of radial scale.
annotations: <GaugeAnnotation>[ GaugeAnnotation( angle: 0, positionFactor: 0.25, widget: Row( children: <Widget>[ Container( width: 100, child: Text( _annotationValue, style: TextStyle( fontFamily: 'Times', fontSize: 22, fontWeight: FontWeight.w400, fontStyle: FontStyle.italic), ), ), ], )), ],
Step 5: Update the value of range pointer and text of the gauge annotation in real time to display the progress. In this demo, the value of range pointer and text of annotation are updated periodically by using a timer.
@override void initState() { _random = Random(); _timer = Timer.periodic(const Duration(milliseconds: 1200), (_timer) { setState(() { int _value = _random.nextInt(100); if (_value > 4 && _value < 100) { _pointerValue = _value.toDouble(); _annotationValue = _value.toString() + ' %'; } }); }); super.initState(); }
Output
You can download the sample from this link.