Flutter绘制虚线

作者: TryEnough | 来源:发表于2019-04-28 11:28 被阅读13次

欢迎去看原文:http://tryenough.com/flutter-dotline

效果

实现方案

方案一:

如果你用canvas画,可以参考这个库来绘制虚线:

https://pub.dartlang.org/packages/path_drawing#-installing-tab-

欢迎去看原文:http://tryenough.com/flutter-dotline

方案二:

定义分割线

class MySeparator extends StatelessWidget {
  final double height;
  final Color color;

  const MySeparator({this.height = 1, this.color = Colors.black});

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
      builder: (BuildContext context, BoxConstraints constraints) {
        final boxWidth = constraints.constrainWidth();
        final dashWidth = 10.0;
        final dashHeight = height;
        final dashCount = (boxWidth / (2 * dashWidth)).floor();
        return Flex(
          children: List.generate(dashCount, (_) {
            return SizedBox(
              width: dashWidth,
              height: dashHeight,
              child: DecoratedBox(
                decoration: BoxDecoration(color: color),
              ),
            );
          }),
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          direction: Axis.horizontal,
        );
      },
    );
  }
}

使用 const MySeparator()

class App extends StatelessWidget {
  const App();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Material(
        child: Container(
          color: Colors.blue,
          child: Center(
            child: Container(
              height: 600, width: 350,
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(16.0)),
              ),
              child: Flex(
                direction: Axis.vertical,
                children: [
                  Expanded(child: Container()),
                  const MySeparator(color: Colors.grey),
                  Container(height: 200),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}

欢迎去看原文:http://tryenough.com/flutter-dotline

相关文章

  • flutter draw虚线问题

    这是一个很好的绘制虚线的办法: 在flutter 中 canvas 没有直接绘制虚线的方法, 但是有drawlin...

  • Flutter绘制虚线

    欢迎去看原文:http://tryenough.com/flutter-dotline 效果 实现方案 方案一: ...

  • Flutter 绘制虚线dashline

    实现Flutter 绘制虚线dashline 话不多说,线上效果图 源码 使用

  • Flutter绘制弯曲虚线

    效果 开始 修改main.dart文件: 去看原文:http://tryenough.com/flutter-cu...

  • Flutter - 绘制弯曲的虚线

    在本文中,我们将绘制如下的弯曲虚线: 我想你已经熟悉了如何在Flutter中绘制自定义形状和线条。如果没有,你可以...

  • iOS 绘制虚线

    /** ** lineView: 需要绘制成虚线的view ** lineLength: 虚线的宽度 ** ...

  • iOS开发绘制虚线的方法

    iOS开发绘制虚线的方法 方法一:通过Quartz 2D 在 UIView drawRect:方法进行绘制虚线 -...

  • IOS绘制虚线的方法总结

    一、重写drawRect方法 二、采用CAShapeLayer方式绘制虚线 三、经济实惠型:采用贴图的方式绘制虚线...

  • iOS两种绘制虚线的方法

    个人CSND 一、绘制单条的虚线 二、给一个控件添加虚线 1、绘制单条的虚线 样式1:------- 2、给一个控...

  • Androidz中Drawable绘制虚线

    Android绘制虚线有很多种方式,常用的就是通过drawable资源绘制虚线。示例代码如下: android:s...

网友评论

    本文标题:Flutter绘制虚线

    本文链接:https://www.haomeiwen.com/subject/wafdnqtx.html