flutter学习之旅-进度条自定义控件

6 篇文章 0 订阅

控件是长这样的
请添加图片描述
代码实现是这样的



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

class RefoundDetailProgress extends StatelessWidget {
  const RefoundDetailProgress({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Stack(
          children: [
            _progressView(1),
            _ProgressCircle(1),
          ],
        ),
        textProgress(1)
      ],
    );
  }

  Widget _progressView(int type) {
     double value = 0;
      switch (type){
        case 0:
          value = 0;
          break;
        case 1:
          value = 0.5;
          break;
        case 2:
          value = 1;
          break;
      }
      return Container(
        alignment: Alignment.center,
        margin: const EdgeInsets.fromLTRB(64, 28, 64, 0),
        child: SizedBox(
          height: 4,
          child: LinearProgressIndicator(
            value: value,
            backgroundColor: const Color(0xffdddddd),
            valueColor: const AlwaysStoppedAnimation<Color>(Color(0xff007EFF)),
          ),
        ),
      );
  }

  Widget _ProgressCircle(int type){
    return Container(
      alignment: Alignment.center,
      margin: const EdgeInsets.fromLTRB(62, 20, 62, 0),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        //向外扩展布局
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: circleChildren(type),
      ),
    );
  }

  List<Widget> circleChildren(int type) {
    List<Widget> circleList = [];
    for (int i = 0; i < 3; i++) {
      if (type == i) {
        circleList.add(Image.asset(
          'assets/images/select_pay.png',
          height: 18,
          width: 18,
        ));
      } else {
        circleList.add(Container(
          width: 10,
          height: 10,
          decoration: BoxDecoration(
              color: type < i ? const Color(0xffdddddd) : const Color(0xff007EFF),
              borderRadius: const BorderRadius.all(Radius.circular(5))),
        ));
      }
    }
    return circleList;
  }

  Widget textProgress(int type) {
    return Container(
      alignment: Alignment.center,
      margin: const EdgeInsets.fromLTRB(43, 10, 43, 0),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        //向外扩展布局
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: textChildren(type),
      ),
    );
  }

  List<Widget> textChildren(int type) {
    List<String> text = ['申请退款','申请已通过','退款成功'];
    List<Widget> textList = [];
    for (int i = 0; i< 3; i++) {
        textList.add(Text(text[i],style: TextStyle(
          fontWeight: FontWeight.w300,
          fontSize: 14,
          color:  type >= i ? const Color(0xff007EFF) : const Color(0xff333333)
        ),));
    }
    return textList;
  }

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值