Sleek circular slider/progress bar for Flutter

License: MITAuthor's website

A highly customizable circular slider/progress bar for Flutter.

Example 01 Example 02 Example 03 Example 04 Example 05 Example 06 Example 07 Example 08

Getting Started

Installation

Add


sleek_circular_slider : ^lastest_version

to your pubspec.yaml, and run

flutter packages get

in your project's root directory.

Basic Usage

Import it to your project file

import 'package:sleek_circular_slider/sleek_circular_slider.dart';

And add it in its most basic form like it:

final slider = SleekCircularSlider(
                      appearance: CircularSliderAppearance(),
                      onChange: (double value) {
                        print(value);
                      });

There are additional optional parameters one can initialize the slider with.

final slider = SleekCircularSlider(
  appearance: CircularSliderAppearance(),
  min: 0,
  max: 1000,
  initialValue: 426,
  onChange: (double value) {
    // callback providing a value while its being changed (with a pan gesture)
  },
  onChangeStart: (double startValue) {
    // callback providing a starting value (when a pan gesture starts)
  },
  onChangeEnd: (double endValue) {
    // ucallback providing an ending value (when a pan gesture ends)
  },
  innerWidget: (double value) {
    // use your custom widget inside the slider (gets a slider value from the callback)
  },
);

Use as a progress bar

Slider user's interaction will be disabled if there is either no onChange or onChangeEnd provided. That way one can use the widget not as a slider but as a progress bar.

final slider = SleekCircularSlider(
  appearance: CircularSliderAppearance(
    customWidths: CustomSliderWidths(progressBarWidth: 10)),
  min: 10,
  max: 28,
  initialValue: 14,
);

SleekCircularSlider parameters

ParameterDefaultDescription
appearance CircularSliderAppearanceA set of objects describing the slider look and feel.
min double0The minimum value the user can select. Must be less than or equal to max.
max double100The maximum value the user can select. Must be greater than or equal to min.
initialValue double50The initial value for this slider.
onChange OnChange(double value)Called during a drag when the user is selecting a new value for the slider by dragging.
onChangeStart OnChange(double value)Called when the user starts selecting a new value for the slider.
onChangeEnd OnChange(double value)Called when the user is done selecting a new value for the slider.
innerWidget Widget InnerWidget(double value)A custom widget to replace the build in text labels which can capture a slider value from the callback.

CircularSliderAppearance parameters

ParameterDefaultDescription
size double150The width & height value for the slider.
startAngle double150The angle (in degrees) the slider begins with.
angleRange double240The angle range (in degrees) the slider reaches when maximum value set.
customWidths CustomSliderWidthsThe object with a set of widths for the track, bar, shadow etc.
customColors CustomSliderColorsThe object with a set of colors for the track, bar, shadow etc.
infoProperties InfoPropertiesThe object with a set of properties for internal labels displaying a current slider value.
animationEnabled booltrueThe setting indicating whether external changes of a slider value should be animated.

CustomSliderWidths parameters

ParameterDefaultDescription
trackWidth doubleprogressBarWidth / 4The width of the slider's track.
progressBarWidth doubleslider's size / 10The width of the slider's progress bar.
shadowWidth doubleprogressBarWidth * 1.4The width of the slider's shadow.
handlerSize doubleprogressBarWidth / 5The size of the slider's handler.

CustomSliderColors parameters

ParameterDefaultDescription
trackColor Color#DCBEFBThe color of the slider's track.
progressBarColor ColorThe color of the slider's progress bar. Won't be used if the slider uses gradient progressBarColors != null
progressBarColors List#1E003B, #EC008A, #6285DAThe list of colors for the progress bar's gradient.
gradientStartAngle double0The start angle for the progress bar's gradient.
gradientEndAngle double180The end angle for the progress bar's gradient.
dotColor Color#FFFFFFThe color of the slider's handle.
hideShadow boolfalseThe setting indicating whether the shadow should be showed.
shadowColor Color#2C57C0The color of the shadow.
shadowMaxOpacity double0.2The opacity of the shadow in its darker part.
shadowStep doubleThe shadow is being painted with a number of steps. This value determines how big is a width of each step. The more steps are painted the softer the shadow is. For a flat shadow use a difference between the shadowWidth and the progressWidth for the shadowStep.

InfoProperties parameters

ParameterDefaultDescription
mainLabelStyle TextStyleThe text style of the main text widget displaying a slider's current value.
topLabelStyle TextStyleThe text style of the top text widget.
bottomLabelStyle TextStyleThe text style of the bottom text widget.
topLabelText StringThe text for the top text widget.
bottomLabelText StringThe text for the bottom text widget.
modifier String PercentageModifier(double percentage)closure adding the % characterThe closure allowing to modify how a current value of the slider is displayed.

Example of the modifier

 String percentageModifier(double value) {
    final roundedValue = value.ceil().toInt().toString();
    return '$roundedValue %';
  }

It will convert a current value to int and add the % sufix to it.

YouTube video

YouTube Video of the example in action

Todo

  • add divisions;
  • add more comments to document the code;

Acknowledgments

  • Hat tip to David Anaya for his awesome blog post about building a circular slider in Flutter and radian to degrees conversions which helped me a lot!

Libraries

sleek_circular_slider