Flutter组件学习(9)进度条

介绍

Material 组件库中提供了两种进度指示器:LinearProgressIndicatorCircularProgressIndicator,它们都可以同时用于精确的进度指示和模糊的进度指示。精确进度通常用于任务进度可以计算和预估的情况,比如文件下载;而模糊进度则用户任务进度无法准确获得的情况,如下拉刷新,数据提交等。

LinearProgressIndicator和CircularProgressIndicator

常用属性

value

表示当前的进度,取值范围为[0,1];

valuenull时则指示器会执行一个循环动画(模糊进度);

value不为null时,指示器为一个具体进度的进度条

backgroundColor指示器的背景色
valueColor

指示器的进度条颜色,该值类型是Animation<Color>,这允许我们对进度条的颜色也可以指定动画。

如果我们想对进度条应用一种固定的颜色,此时我们可以通过AlwaysStoppedAnimation来指定

CircularProgressIndicator

 

strokeWidth表示圆形进度条的粗细

demo

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main(){
  runApp(MyApp());
}

class MyApp extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.red,
          title: Text(
            '进度条指示器练习',
            style: TextStyle(fontSize: 18, color: Colors.yellow),
          ),
        ),
        body: IndicatorTest(),
      ),
    );
  }
}

class IndicatorTest extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Column(
      children: <Widget>[

        Container(
          margin: EdgeInsets.all(20),
          child: LinearProgressIndicator(
            backgroundColor: Colors.blue[200],
            valueColor: AlwaysStoppedAnimation(Colors.yellow),
          ),
        ),

        SizedBox(height: 20,),

        Container(
          margin: EdgeInsets.all(20),
          child: LinearProgressIndicator(
            backgroundColor: Colors.blue,
            valueColor: AlwaysStoppedAnimation(Colors.yellow),
            value: 0.8,
          ),
        ),

        SizedBox(height: 20,),

        Container(
          margin: EdgeInsets.all(20),
          child: CircularProgressIndicator(
            backgroundColor: Colors.blue,
            valueColor: AlwaysStoppedAnimation(Colors.yellow),
          ),
        ),

        SizedBox(height: 20,),

        Container(
          width: 100,
          height: 100,
          margin: EdgeInsets.all(20),
          child: CircularProgressIndicator(
            backgroundColor: Colors.blue,
            valueColor: AlwaysStoppedAnimation(Colors.yellow),
            value: 0.5,
          ),
        ),
      ],
    );
  }

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小小苏的小小苏

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值