Flutter基础组件Checkbox,Switch,进度指示器

Checkbox 和 Switch

Checkbox的大小是固定的,无法自定义,而Switch只能定义宽度,高度也是固定的

import 'package:flutter/material.dart';

class StudyCheckbox extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Checkbox和Switch"),
      ),
      body: Container(
        child: SwitchAndCheckboxRoute(),
      )
    );
  }

}
class SwitchAndCheckboxRoute extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    return SwitchAndCheckboxRouteState();
  }
}
class SwitchAndCheckboxRouteState extends State<SwitchAndCheckboxRoute>{
  bool switchSelect = false; //单选开关状态
  bool checkboxSelect = false;//复选开关状态
  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Switch(
          value: switchSelect,
          onChanged: (value){
            setState(() {
              switchSelect = value;
            });
          },
        ),
        Checkbox(
          value: checkboxSelect,
          onChanged: (value){
            setState(() {
              checkboxSelect = value!;
            });
          },
          activeColor: Colors.purple,//选中时的颜色
        )
      ],
    );
  }

}

未选中效果
在这里插入图片描述
选中效果
在这里插入图片描述

进度指示器

Material 组件库中提供了两种进度指示器:LinearProgressIndicator和CircularProgressIndicator。

LinearProgressIndicator

LinearProgressIndicator是一个线性、条状的进度条。

value:

value表示当前的进度,取值范围为[0,1];如果value为null时则指示器会执行一个循环动画(模糊进度);当value不为null时,指示器为一个具体进度的进度条。

backgroundColor:

指示器的背景色

valueColor:

指示器的进度条颜色

Text("LinearProgressIndicator",),
  Container(
     margin: const EdgeInsets.fromLTRB(10, 20, 10, 10),
     //在没有给value赋值的情况下会执行循环动画
     child:LinearProgressIndicator(
       backgroundColor: Colors.grey,//指示器背景色
       valueColor: AlwaysStoppedAnimation(Colors.blue),//进度背景色
     ),
     height: 20,
   ),
   Container(
     margin: const EdgeInsets.fromLTRB(10, 20, 10, 10),
     child:LinearProgressIndicator(
       backgroundColor: Colors.grey,//指示器背景色
       valueColor: AlwaysStoppedAnimation(Colors.blue),//进度背景色
       value: 0.2,//进度
     ),
     height: 20,
   ),

在这里插入图片描述

CircularProgressIndicator

strokeWidth 表示圆形进度条的粗细

 Text(" CircularProgressIndicator",),
   Container(
      margin: const EdgeInsets.fromLTRB(10, 20, 10, 10),
      //在没有给value赋值的情况下会执行循环动画
      child:CircularProgressIndicator(
        backgroundColor: Colors.grey,//指示器背景色
        valueColor: AlwaysStoppedAnimation(Colors.blue),//进度背景色
        strokeWidth: 10,
      ),
      width: 100,
      height: 100,
    ),
    Container(
      margin: const EdgeInsets.fromLTRB(10, 20, 10, 10),
      child:CircularProgressIndicator(
        backgroundColor: Colors.grey,//指示器背景色
        valueColor: AlwaysStoppedAnimation(Colors.blue),//进度背景色
        value: 0.6,
        strokeWidth: 10,
      ),
      width: 100,
      height: 100,
    ),

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值