搜索插件、代码仓与 APP 分类

插件详情v2.5.0

flutter_circular_slider

一个可自定义的小部件,用于在圆形线条中选择间隔。

近 30 天下载
89
喜欢数
80
Pub 分数
40

安装插件

flutter pub add flutter_circular_slider

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个可自定义的 Flutter 小部件,专为沿圆形路径选择间隔而设计。它提供了一个直观的界面,让用户通过旋转圆周上的手柄来选择值,非常适合音量控制、角度选择器或时间选择器等设置。该滑块支持颜色、大小和步进增量的自定义,具有平滑的动画和响应式反馈。专为性能和易于集成而构建,可无缝融入现代用户界面设计。

适合场景

  • 音量或亮度控制
  • 设计工具中的角度选择
  • 时间或间隔选择器
  • 带有视觉反馈的自定义数值输入
  • 交互式仪表板元素

主要特点

  • 圆形拖动交互
  • 可配置的弧形范围和步骤
  • 平滑的动画过渡
  • 可自定义的颜色和样式
  • 响应式触摸处理

适合对象

  • 需要径向输入的UI
  • 寻求独特外形的设计人员
  • 带有模拟风格控制的应用程序
  • 带有交互式设置的移动应用
  • 想要可重用圆形控件的开发者

使用建议

  • 限制为循环交互模式
  • 可能需要额外的逻辑来处理非线性值映射
  • 未针对非常大或非常小的屏幕尺寸进行优化
  • 需要对触摸输入精度进行仔细测试
  • 最适合单值选择场景

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

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

所属分类

源码仓库

使用此插件的项目

暂无相关数据。