【Flutter学习】基本组件之进度条(LinearProgressIndicator, CircularProgressIndicator)

 

一,概述

  基本有两种类型:

  • 条形进度条(LinearProgressIndicator
    new LinearProgressIndicator(
    backgroundColor: Colors.blue,
    // value: 0.2,
    valueColor: new AlwaysStoppedAnimation<Color>(Colors.red),
    ),
    new Container(padding: const EdgeInsets.all(20.0)),
  • 圆形进度条(CircularProgressIndicator
    new CircularProgressIndicator(
    strokeWidth: 4.0,
    backgroundColor: Colors.blue,
    // value: 0.2,
    valueColor: new AlwaysStoppedAnimation<Color>(Colors.red),
    ),  

 

注意如果 value 为 null 或空,则显示一个动画,否则显示一个定值。Progress 的值只能设置 0 ~ 1.0,如果大于 1,则表示已经结束。 

二,构造函数

  • LinearProgressIndicator
    复制代码
    /**
    * 条形进度条 * LinearProgressIndicator本身不能设置高度,可以包一层父容器设置高度来间接设置LinearProgressIndicator的高度, * 如Container,SizedBox等 * * const LinearProgressIndicator({ Key key, double value,//0~1的浮点数,用来表示进度多少;如果 value 为 null 或空,则显示一个动画,否则显示一个定值 Color backgroundColor,//背景颜色 Animation<Color> valueColor,//animation类型的参数,用来设定进度值的颜色,默认为主题色 String semanticsLabel, String semanticsValue, }) */
    复制代码
  • CircularProgressIndicator
    复制代码
    /**
     * 圆形进度条
     * 可以在外面包一层SizedBox,间接改变进度条的大小
     *const CircularProgressIndicator({
        Key key,
        double value,//0~1的浮点数,用来表示进度多少;如果 value 为 null 或空,则显示一个动画,否则显示一个定值
        Color backgroundColor,//背景颜色
        Animation<Color> valueColor,//animation类型的参数,用来设定进度值的颜色,默认为主题色
        this.strokeWidth = 4.0,//进度条宽度
        String semanticsLabel,
        String semanticsValue,
        })
     */
    复制代码

三,demo

  • LinearProgressIndicator
    复制代码
    body: ListView(
              children: <Widget>[
                Container(
                  padding: EdgeInsets.only(left: 50.0, right: 50.0, top: 50.0),
                  child: LinearProgressIndicator(
                    value: 0.3,
                    backgroundColor: Color(0xff00ff00),
                  ),
                ),
                Container(
                  padding: EdgeInsets.only(left: 50.0, right: 50.0, top: 50.0),
                  child: LinearProgressIndicator(
    //                    value: 0.3,
                    backgroundColor: Color(0xffff0000),
                  ),
                ),
                Container(
                  padding: EdgeInsets.only(left: 50.0, right: 50.0, top: 50.0),
                  child: LinearProgressIndicator(
                    value: 0.3,
                    valueColor: new AlwaysStoppedAnimation<Color>(Colors.red),
                    backgroundColor: Color(0xff00ff00),
                  ),
                ),
                Container(
                  padding: EdgeInsets.only(left: 50.0, right: 50.0, top: 50.0),
                  child: Container(
                    height: 10.0,
                    child: LinearProgressIndicator(
                      value: 0.3,
                      valueColor: new AlwaysStoppedAnimation<Color>(Colors.red),
                      backgroundColor: Color(0xff00ff00),
                    ),
                  ),
                ),
              ],
            ),
    复制代码
  • CircularProgressIndicator
    复制代码
    body: Stack(
                children: <Widget>[
                  Positioned(
                      left: 150.0,
                      top: 20.0,
                      child: CircularProgressIndicator(
    //                    value: 0.3,
                        backgroundColor: Color(0xffff0000),
                      )
                  ),
                  Positioned(
                      left: 150.0,
                      top: 70.0,
                      child: CircularProgressIndicator(
                        value: 0.3,
                        backgroundColor: Color(0xffff0000),
                      )
                  ),
                  Positioned(
                      left: 150.0,
                      top: 120.0,
                      child: CircularProgressIndicator(
    //                    value: 0.3,
                        strokeWidth: 4.0,
                        backgroundColor: Color(0xffff0000),
                        valueColor: new AlwaysStoppedAnimation<Color>(Colors.red),
                      )
                  ),
                  Positioned(
                      left: 150.0,
                      top: 170.0,
                      child: CircularProgressIndicator(
    //                    value: 0.3,
                        strokeWidth: 8.0,
                        backgroundColor: Color(0xffff0000),
                        valueColor: new AlwaysStoppedAnimation<Color>(Colors.red),
                      )
                  ),
                  Positioned(
                      left: 150.0,
                      top: 220.0,
                      child: SizedBox(
                        width: 50.0,
                        height: 50.0,
                        child: CircularProgressIndicator(
    //                    value: 0.3,
                          backgroundColor: Color(0xffff0000),
                          valueColor: new AlwaysStoppedAnimation<Color>(Colors.red),
                        ),
                      )
                  ),
                ],
              )
    复制代码

     

 

posted on   梁飞宇  阅读(10704)  评论(0编辑  收藏  举报

编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
历史上的今天:
2018-07-09 dyld环境变量
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示