How to create Circular or Linear percentage Progress Bar

If you want to build a progress bar indicator that is either circular or linear different than the default progress bar indicator which looks more beautiful then see the example below. In this example, We have used the flutter package which helps to make this very easy. And we can easily apply the percentage on it and the progress text.

For this custom progress bar indicator, you need to add percent_indicator flutter package in your dependency by adding the following line in pubspec.yaml file.

dependencies:
  flutter:
    sdk: flutter
  percent_indicator: ^2.1.3

Circular Progress Bar Indicator with percentage basic code:

CircularPercentIndicator(
   radius: 60.0,
   lineWidth: 5.0,
   percent: 0.8,
   center: new Text("80%"),
   progressColor: Colors.green,
)

Liner Progress Bar Indicator with percentage basic code:

LinearPercentIndicator(
   width: 140.0,
   lineHeight: 14.0,
   percent: 0.5,
   backgroundColor: Colors.grey,
   progressColor: Colors.blue,
),

Full Flutter dart code:

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:percent_indicator/percent_indicator.dart';

class MyProgressIndicator extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
     return Scaffold(
        appBar: AppBar(
          title:Text("Custom Progress Indicator"),
          backgroundColor: Colors.redAccent
        ),
        body:Container( 
            child:Column(
              children: <Widget>[ 
                  Container(
                     padding: EdgeInsets.all(10),
                     child: CircularPercentIndicator( //circular progress indicator
                      radius: 120.0, //radius for circle
                      lineWidth: 15.0, //width of circle line
                      animation: true, //animate when it shows progress indicator first
                      percent: 60/100, //vercentage value: 0.6 for 60% (60/100 = 0.6)
                      center: Text("60.0%",style: TextStyle(
                        fontWeight: FontWeight.bold, fontSize: 20.0),
                      ), //center text, you can set Icon as well
                      footer: Text("Order this Month", style:TextStyle( 
                        fontWeight: FontWeight.bold, fontSize: 17.0),
                      ), //footer text 
                      backgroundColor: Colors.lightGreen[300], //backround of progress bar
                      circularStrokeCap: CircularStrokeCap.round, //corner shape of progress bar at start/end
                      progressColor: Colors.redAccent, //progress bar color
                    )
                  ),

                  Container(
                     padding: EdgeInsets.all(10),
                     child: LinearPercentIndicator( //leaner progress bar
                        width: 210, //width for progress bar
                        animation: true, //animation to show progress at first
                        animationDuration: 1000,
                        lineHeight: 30.0, //height of progress bar
                        leading: Padding( //prefix content
                           padding: EdgeInsets.only(right:15),
                           child:Text("left content"), //left content
                        ),
                        trailing: Padding( //sufix content
                          padding: EdgeInsets.only(left:15),
                          child:Text("right content"), //right content
                        ),
                        percent: 0.3, // 30/100 = 0.3
                        center: Text("30.0%"),
                        linearStrokeCap: LinearStrokeCap.roundAll, //make round cap at start and end both
                        progressColor: Colors.redAccent, //percentage progress bar color
                        backgroundColor: Colors.orange[100],  //background progressbar color
                      ),
                  )
              ],
            )
        )
     );
  }

}

In this way, you can create a beautiful custom Circular or linear progress bar with the percentage.

No any Comments on this Article


Please Wait...