flutter seekbar 可拖拽可点击的进度条

flutter seekbar

wechat :674668211 加微信进flutter微信群
掘金: https://juejin.im/user/581206302f301e005c60cd2f
简书:https://www.jianshu.com/u/4a5dce56807b
csdn:https://me.csdn.net/liu__520
github : https://github.com/LiuC520/

A beautiful flutter custom seekbar, which has a bubble view with progress appearing upon when seeking. 自定义SeekBar,进度变化更以可视化气泡样式呈现

效果图

screenshot.gif

引入:
dependencies:
  flutter:
    sdk: flutter
  flutter_seekbar:
    git: https://github.com/LiuC520/flutter_seekbar.git
属性
Attribute 属性默认值Description 描述
min0.0最小值
max100.0最大值
value0.0默认进度值
backgroundColor页面配置的backgroundColor进度条背景颜色
progressColoraccentColor当前进度的颜色
progresseight5进度条的高度
sectionCount1进度条分为几段
sectionColor当前进度的颜色进度条每一个间隔的圆圈的颜色
sectionUnSelecteColor进度条的背景颜色间隔未选中的颜色
sectionRadius0.0间隔圆的半径
showSectionTextfalse是否显示刻度值
sectionTexts空数组自定义刻度值,是个数组,数组必须是SectionTextModel的实体
sectionTextSize14刻度值字体的大小
afterDragShowSectionTextfalse是否在拖拽结束后显示刻度值
sectionTextColor黑色刻度值字体的颜色
sectionSelectTextColor透明(Colors.transparent)选中的刻度值字体的颜色
sectionDecimal0刻度值的小数点位数
sectionTextMarginTop4.0刻度值距离进度条的间距
indicatorRadius进度条的高度 + 2中间指示器圆圈的半径
indicatorColor进度条当前进度的颜色中间指示器圆圈的颜色
semanticsLabel这个是给盲人用的,屏幕阅读器的要读出来的标签
semanticsValue这个是给盲人用的,屏幕阅读器的要读出的进度条的值
onValueChanged默认是空方法进度改变的回调,是ProgressValue的实体,里面包含了进度,0-1,还包含了当前的进度值
isRoundtrue ( 圆角 )圆角还是直角,圆角的默认半径是进度条高度的一半
hideBubbletrue是否显示气泡,默认是隐藏
alwaysShowBubblefalse是否一致显示气泡,默认是false,也就是只有在拖拽的时间才显示气泡,拖拽结束不显示
bubbleRadius20气泡的半径
bubbleHeight60气泡的总高度,包含顶部圆形的半径,默认是气泡半径的3倍
bubbleColor当前进度条的颜色气泡的背景颜色
bubbleTextColor白色气泡中当前进度值的字体颜色,默认是白色
bubbleTextSize14气泡中当前进度值的字体大小,默认是14
bubbleMargin4气泡底部距离进度条的高度,默认是4
bubbleInCenterfalse气泡是否在进度条的中间显示,默认是

Example

1、首先在pubspec.yaml中添加依赖

dependencies:
  flutter:
    sdk: flutter
  flutter_seekbar:
        git: https://github.com/LiuC520/flutter_seekbar.git

2、示例

import 'package:flutter_seekbar/flutter_seekbar.dart' show ProgressValue, SectionTextModel, SeekBar;



class Home extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _HomeState();
  }
}

class _HomeState extends State<Home> with SingleTickerProviderStateMixin {
  List<SectionTextModel> sectionTexts = [];

  @override
  void initState() {
    super.initState();
    sectionTexts.add(
        SectionTextModel(position: 0, text: 'bad', progressColor: Colors.red));
    sectionTexts.add(SectionTextModel(
        position: 2, text: 'good', progressColor: Colors.yellow));
    sectionTexts.add(SectionTextModel(
        position: 4, text: 'great', progressColor: Colors.green));
  }

  @override
  Widget build(BuildContext context) {
      return SingleChildScrollView(
        child: Container(
            padding: EdgeInsets.fromLTRB(0, 80, 0, 0),
            child: Column(
              children: <Widget>[
                Column(
                  children: <Widget>[
                    Container(
                        width: 200,
                        child: SeekBar(
                          progresseight: 10,
                          indicatorRadius: 0.0,
                          value: 0.2,
                          isRound: false,
                        )),
                    Text(
                      "直角",
                      style: TextStyle(fontSize: 10),
                    ),
                  ],
                ),
                Padding(
                  padding: EdgeInsets.fromLTRB(0, 40, 0, 0),
                  child: Column(
                    children: <Widget>[
                      Container(
                          width: 200,
                          child: SeekBar(
                              indicatorRadius: 0.0,
                              progresseight: 5,
                              value: 0.6,
                              hideBubble: false,
                              alwaysShowBubble: true,
                              bubbleRadius: 14,
                              bubbleColor: Colors.purple,
                              bubbleTextColor: Colors.white,
                              bubbleTextSize: 14,
                              bubbleMargin: 4,
                              bubbleInCenter: true)),
                      Text(
                        "圆角,气泡居中,始终显示气泡",
                        style: TextStyle(fontSize: 10),
                      ),
                    ],
                  ),
                ),
                Padding(
                  padding: EdgeInsets.fromLTRB(0, 40, 0, 0),
                  child: Column(
                    children: <Widget>[
                      Container(
                          padding: EdgeInsets.fromLTRB(0, 0, 0, 6),
                          width: 200,
                          child: SeekBar(
                            progresseight: 5,
                            value: 0.2,
                          )),
                      Text(
                        "圆角带指示器",
                        style: TextStyle(fontSize: 10),
                      ),
                    ],
                  ),
                ),
                Padding(
                  padding: EdgeInsets.fromLTRB(0, 40, 0, 0),
                  child: Column(
                    children: <Widget>[
                      Container(
                          padding: EdgeInsets.fromLTRB(0, 0, 0, 6),
                          width: 200,
                          child: SeekBar(
                            progresseight: 5,
                            value: 0.5,
                            sectionCount: 5,
                          )),
                      Text(
                        "带间隔带指示器",
                        style: TextStyle(fontSize: 10),
                      )
                    ],
                  ),
                ),
                Padding(
                  padding: EdgeInsets.fromLTRB(0, 40, 0, 0),
                  child: Column(
                    children: <Widget>[
                      Container(
                          padding: EdgeInsets.fromLTRB(0, 0, 0, 6),
                          width: 200,
                          child: SeekBar(
                            progresseight: 5,
                            value: 0.5,
                            sectionCount: 4,
                            sectionRadius: 6,
                            sectionColor: Colors.red,
                          )),
                      Text(
                        "带间隔画间隔的指示器",
                        style: TextStyle(fontSize: 10),
                      )
                    ],
                  ),
                ),
                Padding(
                  padding: EdgeInsets.fromLTRB(0, 40, 0, 0),
                  child: Column(
                    children: <Widget>[
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        mainAxisSize: MainAxisSize.min,
                        children: <Widget>[
                          Text('-10'),
                          Container(
                              margin: EdgeInsets.fromLTRB(10, 0, 10, 4),
                              width: 200,
                              child: SeekBar(
                                  progresseight: 5,
                                  value: 0.5,
                                  min: -10,
                                  max: 80,
                                  sectionCount: 4,
                                  sectionRadius: 6,
                                  sectionColor: Colors.red,
                                  hideBubble: false,
                                  alwaysShowBubble: true,
                                  bubbleRadius: 14,
                                  bubbleColor: Colors.purple,
                                  bubbleTextColor: Colors.white,
                                  bubbleTextSize: 14,
                                  bubbleMargin: 4,
                                  onValueChanged: (v) {
                                    print(
                                        '当前进度:${v.progress} ,当前的取值:${v.value}');
                                  })),
                          Text('80')
                        ],
                      ),
                      Text(
                        "带间隔带气泡的指示器,气泡",
                        style: TextStyle(fontSize: 10),
                      )
                    ],
                  ),
                ),
                Padding(
                  padding: EdgeInsets.fromLTRB(0, 40, 0, 0),
                  child: Column(
                    children: <Widget>[
                      Container(
                          margin: EdgeInsets.fromLTRB(0, 0, 0, 40),
                          width: 200,
                          child: SeekBar(
                            progresseight: 10,
                            value: 0.5,
                            sectionCount: 4,
                            sectionRadius: 5,
                            sectionColor: Colors.red,
                            sectionUnSelecteColor: Colors.red[100],
                            showSectionText: true,
                            sectionTextMarginTop: 2,
                            sectionDecimal: 0,
                            sectionTextColor: Colors.black,
                            sectionSelectTextColor: Colors.red,
                            sectionTextSize: 14,
                          )),
                      Text(
                        "带带刻度的指示器,可设置刻度的样式和选中的刻度的样式",
                        style: TextStyle(fontSize: 10),
                      )
                    ],
                  ),
                ),
                Padding(
                  padding: EdgeInsets.fromLTRB(0, 40, 0, 0),
                  child: Column(
                    children: <Widget>[
                      Container(
                          margin: EdgeInsets.fromLTRB(0, 0, 0, 40),
                          width: 200,
                          child: SeekBar(
                            progresseight: 10,
                            value: 0.5,
                            sectionCount: 4,
                            sectionRadius: 5,
                            sectionColor: Colors.red,
                            sectionUnSelecteColor: Colors.red[100],
                            showSectionText: true,
                            sectionTextMarginTop: 2,
                            sectionDecimal: 0,
                            sectionTextColor: Colors.black,
                            sectionSelectTextColor: Colors.red,
                            sectionTextSize: 14,
                            hideBubble: false,
                            bubbleRadius: 14,
                            bubbleColor: Colors.purple,
                            bubbleTextColor: Colors.white,
                            bubbleTextSize: 14,
                            bubbleMargin: 4,
                            afterDragShowSectionText: true,
                          )),
                      Text(
                        "带带刻度的指示器,可设置刻度的样式和选中的刻度的样式,拖拽结束显示刻度值,拖拽开始显示气泡",
                        style: TextStyle(fontSize: 10),
                      )
                    ],
                  ),
                ),
                Padding(
                  padding: EdgeInsets.fromLTRB(0, 40, 0, 0),
                  child: Column(
                    children: <Widget>[
                      Container(
                          margin: EdgeInsets.fromLTRB(0, 0, 0, 40),
                          width: 200,
                          child: SeekBar(
                            min: -100,
                            max: 200,
                            progresseight: 10,
                            value: 0.75,
                            sectionCount: 4,
                            sectionRadius: 6,
                            showSectionText: true,
                            sectionTexts: [],
                            sectionTextMarginTop: 2,
                            sectionDecimal: 0,
                            sectionTextColor: Colors.black,
                            sectionSelectTextColor: Colors.red,
                            sectionTextSize: 14,
                            hideBubble: false,
                            bubbleRadius: 14,
                            bubbleColor: Colors.purple,
                            bubbleTextColor: Colors.white,
                            bubbleTextSize: 14,
                            bubbleMargin: 4,
                            afterDragShowSectionText: true,
                          )),
                      Text(
                        "自定义刻度值显示,带带刻度的指示器,可设置刻度的样式和选中的刻度的样式,拖拽结束显示刻度值,拖拽开始显示气泡",
                        style: TextStyle(fontSize: 10),
                      )
                    ],
                  ),
                ),
                Padding(
                  padding: EdgeInsets.fromLTRB(0, 40, 0, 0),
                  child: Column(
                    children: <Widget>[
                      Container(
                          margin: EdgeInsets.fromLTRB(0, 0, 0, 40),
                          width: 200,
                          child: SeekBar(
                            progresseight: 10,
                            value: 0.75,
                            sectionCount: 4,
                            sectionRadius: 6,
                            showSectionText: true,
                            sectionTexts: sectionTexts,
                            sectionTextMarginTop: 2,
                            sectionDecimal: 0,
                            sectionTextColor: Colors.black,
                            sectionSelectTextColor: Colors.red,
                            sectionTextSize: 14,
                            hideBubble: false,
                            bubbleRadius: 14,
                            bubbleColor: Colors.purple,
                            bubbleTextColor: Colors.white,
                            bubbleTextSize: 14,
                            bubbleMargin: 4,
                            afterDragShowSectionText: true,
                          )),
                      Text(
                        "自定义刻度值显示,带带刻度的指示器,可设置刻度的样式和选中的刻度的样式,拖拽结束显示刻度值,拖拽开始显示气泡",
                        style: TextStyle(fontSize: 10),
                      )
                    ],
                  ),
                ),
              ],
            )),
      );

  }
}

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值