当前位置: 首页 > news >正文

Flutter 自定义 虚线 分割线

学习使用Flutter 进行 虚线 自定义控件 练习

// 自定义虚线 (默认是垂直方向)
class DashedLind extends StatelessWidget {final Axis axis; // 虚线方向final double dashedWidth; // 根据虚线的方向确定自己虚线的宽度final double dashedHeight; // 根据虚线的方向确定自己虚线的高度final int count; // 内部会根据设置的个数和宽度确定密度(虚线的空白间隔)final Color color; // 虚线的颜色const DashedLind({super.key,required this.axis,this.dashedWidth = 1,this.dashedHeight = 1,this.count = 10,this.color = const Color(0xffaaaaaa)});Widget build(BuildContext context) {return LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) {// 根据宽度计算个数return Flex(direction: axis,mainAxisAlignment: MainAxisAlignment.spaceBetween,children: List.generate(count, (_) {return SizedBox(width: dashedWidth,height: dashedHeight,child: DecoratedBox(decoration: BoxDecoration(color: color),),);}),);});}
}

使用方法:

Widget build(BuildContext context) {return Scaffold(// 脚手架appBar: AppBar(title: Text(widget.title),),body: Center(child: Column(children: [Container (height: 200,child: const DashedLind(axis:Axis.vertical, // 垂直方向设置dashedHeight: 8,count: 12,color: Colors.red,),),Container(width: 200,child: const DashedLind(axis: Axis.horizontal, // 水平方向设置dashedWidth: 6,count: 15,color: Colors.red,),)],),),);}
}

纸上得来终觉浅,绝知此事要躬行。

http://www.lryc.cn/news/95739.html

相关文章:

  • Java毕业设计—爱宠医院管理系统设计与实现
  • AI时代带来的图片造假危机,该如何解决
  • 【动态规划】简单多状态
  • 科技资讯|苹果计划本月推出Vision Pro头显开发套件,电池有重大更新
  • k8s 将pod节点上的文件拷贝到本地
  • Git简介与工作原理:了解Git的基本概念、版本控制系统和分布式版本控制的工作原理
  • java篇 类的进阶0x02:方法重载
  • Android11 相机拍照权限,以及解决resolveActivity返回null
  • MAXENT模型的生物多样性教程
  • CISA学习笔记-第一章、信息系统审计过程
  • 回调函数的使用:案例一:c语言简单信号与槽机制。
  • python matplotlib库 设置字体字号等
  • 【MySQL】SQL性能分析 (七)
  • 超越想象的GPT医疗 20230723
  • 【N32L40X】学习笔记03-gpio输出库
  • WebClient,HTTP Interface远程调用阿里云API
  • 飞书ChatGPT机器人 – 打造智能问答助手实现无障碍交流
  • React、Vue框架如何实现组件更新,原理是什么?
  • 常见面试题之设计模式--策略模式
  • redis多key问题
  • kafka第三课-可视化工具、生产环境问题总结以及性能优化
  • 2_Apollo4BlueLite中断控制器NVIC
  • WAIC2023:图像内容安全黑科技助力可信AI发展
  • 微信小程序quickstartFunctions中云函数的应用
  • Go学习 2、程序结构
  • SpringBoot整合JavaMail
  • Spring6——入门
  • 【计算机视觉 | 目标检测 | 图像分割】arxiv 计算机视觉关于目标检测和图像分割的学术速递(7 月 17 日论文合集)
  • 为什么需要GP(Global Platform)认证?
  • eclipse 格式化代码 快捷键