flutter 自定义时间轴

在这里插入图片描述
复制进项目改一下自己喜欢的样式就可以用
源码如下:



import 'package:flutter/material.dart';

class TimeLine extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text('时间轴'),
      ),
      body: buildContent(true),
    );
  }

  double leftWidth=20;

  //是否签收 当前块可以自己diy
  buildContent(bool result){
    return  Container(
      alignment: Alignment.centerLeft,
      child: Column(
        children: [
          Row(
            children: [
              buildCircle(result),//圆点
              SizedBox(width: 10,),
              Container(
                child: Text('${result?"已签收":"2020-135"}',style: TextStyle(
                    color: result?rgba(95, 142, 255, 1):rgba(153, 153, 153, 1),
                    fontSize: 16
                ),),
                alignment: Alignment.centerLeft,
              )
            ],
          ),
          Row(
            children: [
              buildLine(height: 50),//线条
              SizedBox(width: 10,),
              //右侧字体
              Expanded(child:Container(
                child: Text('签收人签收信息签收人签收信息签收人签收信息签收人签收信息签收人签收信息签收人签收信息',style: TextStyle(
                    color: result?rgba(51, 51, 51, 1):rgba(153, 153, 153, 1),
                    fontSize: 14
                ),),
                alignment: Alignment.centerLeft,
              ),),
            ],
          ),
        ],
      ),
    );
  }


  //物流线条
  // height 线条总高度
  // line:每一个线条高度
  //margin:每个线条间隔
  //width:线条总宽度
  //lineWidth:线条宽度
  buildLine({double height:50,double line:5,double margin:3,double width:1}){
    int length =(height/line+margin).ceil();
    return Container(
      width: leftWidth,//当前线条需要的总宽度
      child: Container(
        width: 12,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: List.generate(length, (index) => Container(
            width: width,
            height: line,
            color: rgba(204, 204, 204, 1),
            margin: EdgeInsets.symmetric(vertical: margin),
          ),
          ),
        ),
      ),
    );
  }


  //圆点
  buildCircle(bool result){
    return Container(
      child: result?Icon(Icons.check):Center(
        child: Container(
          alignment: Alignment.center,
          width: 12,
          height: 12,
          decoration: BoxDecoration(
              color: rgba(204, 204, 204, 1),
              borderRadius: BorderRadius.circular(50)
          ),
        ),
      ),
      width: leftWidth,
    );
  }


  Color rgba(r,g,b,double opacity){
    return Color.fromRGBO(r,g,b,opacity);
  }

}


ovo------ovo

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值