A customizable circular slider for Flutter.

Overview

flutter_circular_slider

Build Status License: MIT Pub

A customizable circular slider for Flutter.

Getting Started

Installation

Add

flutter_circular_slider : ^lastest_version

to your pubspec.yaml, and run

flutter packages get

in your project's root directory.

Basic Usage

Create a new project with command

flutter create myapp

Edit lib/main.dart like this:

import 'package:flutter/material.dart';

import 'package:flutter_circular_slider/flutter_circular_slider.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.blueGrey,
        body: Center(
          child: Container(child: DoubleCircularSlider(100, 0, 20)),
        ));
  }
}

There are two different options:

  • SingleCircularSlider: has only one handler and can be moved either dragging the handler or just by clicking on different parts of the slider.
  • DoubleCircularSlider: has two handlers and both have to be moved by dragging them.

Basic Slider

Constructor

Parameter Default Description
divisions The number of sections in which the circle will be divided for selection.
init (Only for DoubleCircularSlider) The initial value in the selection. Has to be bigger than 0 and smaller than divisions.
end (Only for DoubleCircularSlider) The end value in the selection. Has to be bigger than 0 and smaller than divisions.
position (Only for SingleCircularSlider) The selection. Has to be bigger than 0 and smaller than divisions.
height 220.0 Height of the canvas where the slider is rendered.
width 220.0 Width of the canvas where the slider is rendered.
primarySectors 0 Number of sectors painted in the base circle. Painted in selectionColor.
secondarySectors 0 Number of secondary sectors painted in the base circle. Painted in baseColor.
child null Widget that will be inserted in the center of the circular slider.
onSelectionChange void onSelectionChange(int init, int end, int laps) Triggered every time the user interacts with the slider and changes the init and end values, and also laps.
onSelectionEnd void onSelectionEnd(int init, int end, int laps) Triggered every time the user finish one interaction with the slider.
baseColor Color.fromRGBO(255, 255, 255, 0.1) The color used for the base of the circle.
selectionColor Color.fromRGBO(255, 255, 255, 0.3) The color used for the selection in the circle.
handlerColor Colors.white The color used for the handlers.
handlerOutterRadius 12.0 The radius for the outter circle around the handler.
showRoundedCapInSelection false (Only for SingleCircularSlider) Shows a rounded cap at the edge of the selection slider with no handler.
showHandlerOutter true If true will display an extra ring around the handlers.
sliderStrokeWidth 12.0 The stroke width for the slider (thickness).
shouldCountLaps false If true, onSelectionChange will also return the updated number of laps.

Use Cases

Move complete selection

Move Selection

Single Handler

Sleep Single Slider

Laps

Sleep Single Slider Laps

Sleep Double Slider Laps

Sleep Time Selection

import 'dart:math';

import 'package:flutter/material.dart';

import 'package:flutter_circular_slider/flutter_circular_slider.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: SafeArea(
      child: Container(
          decoration: BoxDecoration(
            image: DecorationImage(
              image: AssetImage('images/background_morning.png'),
              fit: BoxFit.cover,
            ),
          ),
          child: SleepPage()),
    ));
  }
}

class SleepPage extends StatefulWidget {
  @override
  _SleepPageState createState() => _SleepPageState();
}

class _SleepPageState extends State<SleepPage> {
  final baseColor = Color.fromRGBO(255, 255, 255, 0.3);

  int initTime;
  int endTime;

  int inBedTime;
  int outBedTime;

  @override
  void initState() {
    super.initState();
    _shuffle();
  }

  void _shuffle() {
    setState(() {
      initTime = _generateRandomTime();
      endTime = _generateRandomTime();
      inBedTime = initTime;
      outBedTime = endTime;
    });
  }

  void _updateLabels(int init, int end) {
    setState(() {
      inBedTime = init;
      outBedTime = end;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      children: [
        Text(
          'How long did you stay in bed?',
          style: TextStyle(color: Colors.white),
        ),
        DoubleCircularSlider(
          288,
          initTime,
          endTime,
          height: 260.0,
          width: 260.0,
          primarySectors: 6,
          secondarySectors: 24,
          baseColor: Color.fromRGBO(255, 255, 255, 0.1),
          selectionColor: baseColor,
          handlerColor: Colors.white,
          handlerOutterRadius: 12.0,
          onSelectionChange: _updateLabels,
          sliderStrokeWidth: 12.0,
          child: Padding(
            padding: const EdgeInsets.all(42.0),
            child: Center(
                child: Text('${_formatIntervalTime(inBedTime, outBedTime)}',
                    style: TextStyle(fontSize: 36.0, color: Colors.white))),
          ),
        ),
        Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
          _formatBedTime('IN THE', inBedTime),
          _formatBedTime('OUT OF', outBedTime),
        ]),
        FlatButton(
          child: Text('S H U F F L E'),
          color: baseColor,
          textColor: Colors.white,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(50.0),
          ),
          onPressed: _shuffle,
        ),
      ],
    );
  }

  Widget _formatBedTime(String pre, int time) {
    return Column(
      children: [
        Text(pre, style: TextStyle(color: baseColor)),
        Text('BED AT', style: TextStyle(color: baseColor)),
        Text(
          '${_formatTime(time)}',
          style: TextStyle(color: Colors.white),
        )
      ],
    );
  }

  String _formatTime(int time) {
    if (time == 0 || time == null) {
      return '00:00';
    }
    var hours = time ~/ 12;
    var minutes = (time % 12) * 5;
    return '$hours:$minutes';
  }

  String _formatIntervalTime(int init, int end) {
    var sleepTime = end > init ? end - init : 288 - init + end;
    var hours = sleepTime ~/ 12;
    var minutes = (sleepTime % 12) * 5;
    return '${hours}h${minutes}m';
  }

  int _generateRandomTime() => Random().nextInt(288);
}

Sleep Slider

Comments
  • Add onSelectionEnd function parameter to CircularSlider

    Add onSelectionEnd function parameter to CircularSlider

    This pull request adds an additional callback function for when the slider selection has ended. This may be useful in cases where the value of the slider maybe be used to update a value on a server or database. In these cases one could use this function as opposed to onSelectionChange to avoid updating too often.

    opened by kirkeaton 5
  • Click instead of dragging the slider

    Click instead of dragging the slider

    Hi, Great work on the sliders. Just a quick query, lets say there is only one handler, then instead of dragging, is it possible to click somewhere on the circle and the handler to move there. This is similar to how linear slider in flutter would work. Thanks!

    opened by subhash279 4
  • question

    question

    in the article you wrote here

    https://itnext.io/how-to-build-a-circular-slider-in-flutter-cab3fc5312df

    how did you get the line to split the circle ?

    is it possible to have only one hadler ( the thing that you drag ) ?

    Many thanks

    Great work !

    opened by superciccio 3
  • 「onSelectionEnd」 actually holds three parameters, what does each parameter mean?

    「onSelectionEnd」 actually holds three parameters, what does each parameter mean?

    Question

    Nice to meet you. I am new to Dart and want to make good use of this library.

    There is one thing I want to ask.

    Although onSelectionEnd is commented that its definition takes a function with a parameter of (int init, int end) as an argument, it is actually a function that takes three parameters.

    I would like you to teach me the role of each parameter. Thank you.

    My usage

    Center(
      child: SingleCircularSlider(
        12,
        3,
        handlerColor: Colors.black,
        onSelectionEnd: (a, b, c) {
             // I do not figure out what a, b, c parameters mean.
        },
        baseColor: Colors.grey.withOpacity(0.5),
        selectionColor: Colors.deepPurple,
      ),
    ),
    
    スクリーンショット 2019-12-30 15 08 50
    opened by fummicc1 2
  • Is there any way to create half circle?

    Is there any way to create half circle?

    I want to make a design like speedOmeter with the handle and same dragging event like yours. Can you please help me to build that? Or suggest the way to build half circle?

    opened by babulpatel1309 1
  • fix: add support for gestures in scroll view

    fix: add support for gestures in scroll view

    There is a problem when the slider is inside a scroll view, as both the gesture detector from the slider and from the scroll view fight for the control and, surprisingly, the scroll view gets the victory with vertical drags.

    I had to implement my own gesture detector and make sure that this is the one that gets the victory when the user interacts with one of the handlers.

    opened by davidanaya 1
  • Added Several new UI features

    Added Several new UI features

    Added Several new features such as

    • Custom coloring and shapes for handlers
    • Support for Icons on handlers
    • Shadows
    • Borders
    • Gradients
    • Allow decoration and more easy customization
    • Internal clock numbers

    See doc/Circular-Slider.png for example

    opened by edwin-alvarez 0
  • Several UI related improvements

    Several UI related improvements

    Added Several new features such as

    • Custom coloring and shapes for handlers
    • Support for Icons on handlers
    • Shadows
    • Borders
    • Gradients
    • Allow decoration and more easy customization
    • Internal clock numbers
    opened by edwin-alvarez 0
  • base_painter.dart needs more customization

    base_painter.dart needs more customization

    The section lines can be more customizable and I wish for that right now

    https://github.com/davidanaya/flutter-circular-slider/blob/master/lib/src/base_painter.dart#L37-L43

        if (primarySectors > 0) {
          _paintSectors(primarySectors, 8.0, selectionColor, canvas);
        }
    
        if (secondarySectors > 0) {
          _paintSectors(secondarySectors, 6.0, baseColor, canvas);
        }```
    
    the `radiusPadding` can be made customizable and the secondarySector should not use the baseColor, but rather allow a custom one and default to baseColor
    opened by SwissCheese5 0
  • migrated to null safety

    migrated to null safety

    please have a look and let me know if any further changes required. I migrated the project to null-safety and run flutter create . command in example directory to create ios, android and web project.

    opened by Faiizii 2
  • Added Several new features

    Added Several new features

    Added Several new features such as

    • Custom coloring and shapes for handlers
    • Support for Icons on handlers
    • Shadows
    • Borders
    • Gradients
    • Allow decoration and more easy customization
    • Internal clock numbers
    opened by edwin-alvarez 1
  • Limiting the range

    Limiting the range

    Any tip on how would you implement constraints like:

    • defining MIN and MAX allowed values (at the beginning and at the end of a circle)
    • constraining the range so that 'init' value is always less than 'end' value
    • constraining all range values not to exceed [MIN, MAX] range (meaning disabling 'laps')

    For example, if a use case would be selecting time range in a single day, there is no obvious way how to achieve this.

    Thanks!

    opened by despie 3
Releases(v1.0.1)
Flutter custom carousel slider - A carousel slider widget,support custom decoration suitable for news and blog

flutter_custom_carousel_slider A carousel slider Flutter widget, supports custom

Emre 40 Dec 29, 2022
A customizable Flutter library that provides a circular context menu

Flutter Pie Menu ?? A customizable Flutter library that provides a circular context menu similar to Pinterest's. Usage Wrap the widget that will react

Raşit Ayaz 14 Jan 4, 2023
A customizable carousel slider widget in Flutter which supports inifinte scrolling, auto scrolling, custom child widget, custom animations and built-in indicators.

flutter_carousel_widget A customizable carousel slider widget in Flutter. Features Infinite Scroll Custom Child Widget Auto Play Horizontal and Vertic

NIKHIL RAJPUT 7 Nov 26, 2022
A customizable carousel slider for Flutter. Supports infinite sliding, custom indicators, and custom animations with many pre-built indicators and animations.

Flutter Carousel Slider A customizable carousel slider for flutter Screenshots Installing dependencies: flutter_carousel_slider: ^1.0.8 Demo Demo a

Udara Wanasinghe 23 Nov 6, 2022
Flutter circular text widget

Circular Text Widget Installation Add dependency in pubspec.yaml: dependencies: flutter_circular_text: "^0.3.1" Import in your project: import 'pack

Farrukh 98 Dec 28, 2022
CircularProfileAvatar is a Flutter package which allows developers to implement circular profile avatar

CircularProfileAvatar is a Flutter package which allows developers to implement circular profile avatar with border, overlay, initialsText and many other awesome features, which simplifies developers job. It is an alternative to Flutter's CircleAvatar Widget.

Muhammad Adil 85 Oct 5, 2022
A Flutter package to create a nice circular menu using a Floating Action Button.

FAB Circular Menu A Flutter package to create a nice circular menu using a Floating Action Button. Inspired by Mayur Kshirsagar's great FAB Microinter

Mariano Cordoba 198 Jan 5, 2023
Open source Flutter package, simple circular progress bar.

Simple circular progress bar Open source Flutter package, simple circular progress bar. Getting Started Installing Basic Examples Colors Start angle L

null 6 Dec 23, 2022
A simple button that gives you the possibility to transform into a circular one and shows a progress indicator

Progress Button A simple button that gives you the possibility to transform into

Daniel B Schneider 0 Dec 22, 2021
Sample Flutter Drawing App which allows the user to draw onto the canvas along with color picker and brush thickness slider.

DrawApp Sample Flutter Drawing App which allows the user to draw onto the canvas along with color picker and brush thickness slider. All code free to

Jake Gough 226 Nov 3, 2022
Slider Master Animation Flutter Dart

Flutter-animated-Slider ?? ?? untitled.1.mp4 Firt you need to add this in pub yamel : dependencies: carousel_slider: ^4.0.0 Finally import 'package

Hmida 8 Sep 10, 2022
The component created with Flutter using Dart programming language, inspired in Fluid Slider by Ramotion.

Fluid Slider Flutter The component created with Flutter using Dart programming language, inspired in Fluid Slider by Ramotion. About The component was

Wilton Neto 41 Sep 30, 2022
Flutter Slider 🎚 + Emojis 🌻 = 💙

Slidermoji Flutter Slider ??️ + Emojis ?? = ?? About Example showcasing the use of Emojis in Slider Widget. Dependencies demoji Contributing Feel free

null 17 Mar 12, 2021
A customisable height slider for Flutter.

Height Slider Widget for Flutter ✨ Demo ?? Usage class _MyHomePageState extends State<MyHomePage> { int height = 170; @override Widget build(Bu

Coval Solutions 15 Aug 21, 2021
Card-slider-flutter - Implementation of swipeable image cards with dot indicators

card_slider A new Flutter project. Getting Started This project is a starting po

Ryan Egbejule-jalla 1 Sep 17, 2022
Practice building basic animations in apps along with managing app state by BLoC State Management, Flutter Slider.

Practice building basic animations in apps along with managing app state by BLoC State Management including: Cubit & Animation Widget, Flutter Slider.

TAD 1 Jun 8, 2022
It's a universal app template to have a great animated splash screen and liquid slider. Just change the animation if you want (rive) and change the images or colours according to your app.

liquid A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this i

Zikyan Rasheed 28 Oct 7, 2022
An introduction slider has some screens that can use to describe your application.

An introduction slider has some screens that can use to describe your application. You can describe your application's title, description, logo, etc. It comes with several features.

Rahul Chouhan 6 Dec 7, 2022
Boris Gautier 1 Jan 31, 2022