Are you looking to display percentages in your next Flutter app in a visually appealing way?
Look no further!
Flutter brings you a handy and versatile package called the 'Percent indicator.' A wide range of circular and linear percent indicators covers every developer's needs.
By the end of this blog post, you'll be well-equipped to use and customize percent indicators in your Flutter applications.
Percent Indicator is a powerful Flutter package that helps you easily create Circular and Linear percent indicators in your project. The beauty of this package lies in its diversity and the level of customization it permits.
Indicators are commonly used to exhibit progress data more user-friendly and aesthetically pleasingly. With Flutter's Percent Indicator, you can infuse life into your data by meticulously displaying them as progress percentages in a circular or linear style. You can choose the progress color, size, duration of the animation, inserting child widgets, and much more.
The steps for starting with any Flutter plugin are usually straightforward. All it takes is adding the package as a dependency in your project, and voila! You're ready to get going. Let's review the installation process in detail. For this, open the pubspec.yaml file in the root of your project. Now, add the percent_indicator dependency under the dependencies section. Here's how to do it:
1dependencies: 2 flutter: 3 sdk: flutter 4 5 percent_indicator: ^4.2.3
Having added the percent_indicator library in your yaml file, you must run the flutter packages get command in your terminal. This command fetches the package and makes it available for your project. It's equivalent to the 'update your packages in IntelliJ' command.
Once the command is executed successfully, the percent_indicator package will be ready for use in your Flutter app. The next step is to import the package in your Dart file where you want to implement it. To do this, add the following import statement at the top of your Dart file:
1import 'package:percent_indicator/percent_indicator.dart';
Now that you've successfully incorporated the percent_indicator package into your project, we will start exploring the implementation of circular and linear percent indicators.
In the Percent Indicator package, you have two indicators: the Circular Percent Indicator and the Linear Percent Indicator. Both offer a different presentation style but are equally pleasing aesthetically.
Circular percent indicator represents progress in a circular form. With several customizable fields, such as radius, lineWidth, percent, center, and progressColor, you can style the Indicator according to your requirements.
The Linear Percent Indicator, on the other hand, exhibits progression linearly. This Indicator also comes equipped with multiple fields you can customize, including width, lineHeight, percent, backgroundColor, and progressColor.
The choice between circular and linear indicators primarily depends on personal preference, space availability, and the type of aesthetic you aim to establish in your application. Furthermore, both types can coexist in different portions of your application to add more diversity to your design.
The Circular Indicator forms a critical component of the Percent Indicator package, offering a unique and visually pleasing way to display progress data. Let's begin by exploring the basic widget implementation:
1new CircularPercentIndicator( 2 radius: 60.0, 3 lineWidth: 5.0, 4 percent: 1.0, 5 center: new Text("100%"), 6 progressColor: Colors.green, 7)
Here, radius sets the size of the circle, lineWidth specifies the thickness of the progress indicator, percent is where you input the progress percentage, center is an optional field that takes in a widget to be displayed at the center of the indicator (in this example, it's a Text widget), and progressColor lets you choose the color of the progress line.
Now that we've familiarized ourselves with the basic structure let's look at a complete example. The following code generates an application with multiple Circular Percent Indicators, each displaying different percentages of progress:
1Widget build(BuildContext context) { 2 return Scaffold( 3 appBar: new AppBar( 4 title: new Text("Circular Percent Indicators"), 5 ), 6 body: Center( 7 child: ListView( 8 children: <Widget>[ 9 new CircularPercentIndicator( 10 radius: 100.0, 11 lineWidth: 10.0, 12 percent: 0.8, 13 header: new Text("Icon header"), 14 center: new Icon( 15 Icons.person_pin, 16 size: 50.0, 17 color: Colors.blue, 18 ), 19 backgroundColor: Colors.grey, 20 progressColor: Colors.blue, 21 ), 22 ...
In the above example, all the additional parameters are self-explanatory. The header parameter displays a widget above the Circular Percent Indicator – a text widget indicating "Icon header" in this case.
The center parameter takes in a widget displayed at the center of the Circular Percent Indicator. Here it is an icon of a person's pin. This is just the tip of the iceberg. The package offers a variety of customization options that allow you to adjust these indicators with precision, catering to your application's specific needs.
This Percent Indicator is another powerful widget offered by this Indicator package. It represents the progress data in a clear, horizontal, linear form and provides various customizable options to make the indicator fit seamlessly with your application's aesthetic. Let's learn the core structure of this indicator:
1new LinearPercentIndicator( 2 width: 140.0, 3 lineHeight: 14.0, 4 percent: 0.5, 5 backgroundColor: Colors.grey, 6 progressColor: Colors.blue, 7)
In this display, width determines the horizontal length of the line, lineHeight controls the thickness, the percent is where you input the progress data, backgroundColor sets the color for the portion of the line representing the remaining progress, and progressColor sets the color for the completed portion of progress. Understanding the basic structure is crucial. However, to grasp its full potential and ease of use, let's explore a complete example:
1Widget build(BuildContext context) { 2 return Scaffold( 3 appBar: new AppBar( 4 title: new Text("Linear Percent Indicators"), 5 ), 6 body: Center( 7 child: Column( 8 mainAxisAlignment: MainAxisAlignment.center, 9 children: <Widget>[ 10 Padding( 11 padding: EdgeInsets.all(15.0), 12 child: new LinearPercentIndicator( 13 width: 140.0, 14 lineHeight: 14.0, 15 percent: 0.5, 16 center: Text( 17 "50.0%", 18 style: new TextStyle(fontSize: 12.0), 19 ), 20 trailing: Icon(Icons.mood), 21 linearStrokeCap: LinearStrokeCap.roundAll, 22 backgroundColor: Colors.grey, 23 progressColor: Colors.blue, 24 ), 25 ...
In addition to the basic parameters, the center parameter displays a widget at the center of the Linear Percent Indicator – a text widget indicating "50.0%" in this case.
The trailing parameter places an icon or text after the LinearPercentIndicator. In this example, we've placed a 'mood' icon after the indicator.
This comprehensive example showcases how you can integrate linear percent indicators into your Flutter applications to create visually pleasing progress data representations.
While the percent indicators come with default settings, the package offers various options to customize your indicators.
From changing the background color, progress color, and animation settings, to writing text in the center or placing child widgets in various positions – the options are manifold.
In Circular and Linear Percent Indicators:
You can toggle animation settings with the animation field. The indicator will animate from 0 to your specified percent if set to true.
The speed of the animation can be set by the animationDuration field.
The backgroundColor controls the color of the unprogressed portion of the indicator.
The progressColor modifies the color of the progressed portion of the indicator.
In Linear Percent Indicator:
These customization options allow developers to create stunning aesthetics aligned with their app's design scheme.
As a Flutter developer, you might face various challenges while using the Percent Indicator package. These could range from simple setup issues to complex display problems. This section'll discuss some common issues you might encounter and viable solutions to tackle them.
Incorrect Package Version: One of the most common issues you might encounter is using an incorrect version or having a compatibility issue. Always check the official documentation or the pub.dev page to ensure you use the correct version.
Problems during Package Installation: Another potential issue could occur while installing the package. Make sure the syntax in the yaml file is correct and you're following the step-by-step instructions as outlined on the official Percent Indicator page.
Problems with Hot Reload: If you're facing problems with the hot reload feature, restarting the app might solve the problem. Some changes, especially those related to packages or project files, might necessitate a full app restart.
Layout Issues with the Indicator: When it comes to layout problems, ensure that you're setting the width, height, or radius according to the available screen space and the requirements of your application.
The percent indicator library offers a feature-rich, customizable solution for adding progress displays to your Flutter applications. Whether you choose a linear or circular approach, it provides a visually dynamic and interactive user experience. So implement it in your Flutter project, and watch the magic happen!
Tired of manually designing screens, coding on weekends, and technical debt? Let DhiWise handle it for you!
You can build an e-commerce store, healthcare app, portfolio, blogging website, social media or admin panel right away. Use our library of 40+ pre-built free templates to create your first application using DhiWise.