如何给“虚线边框”打分扑扑? [英] How to give a "Dashed Border" in flutter?

查看:112
本文介绍了如何给“虚线边框”打分扑扑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在颤动中设置虚线边框,但在颤动中没有虚线边框选项。

I try to give dashed border in flutter but there is no option for dashed border in flutter. so any another way to create dashed border in futter.

  new Container(
          decoration: new BoxDecoration(
              border: Border(
                  left: BorderSide(color: Color(0XFFFF6D64), width: 2.0))),
          height: 20.0,
          margin: const EdgeInsets.only(left: 35.0),
          child: new Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              new DecoratedBox(
                decoration: new BoxDecoration(
                    border: Border(
                        left:
                            BorderSide(color: Color(0XFFFF6D64), width: 2.0,style: BorderStyle.))),

              )
            ],
          ),
        ),


推荐答案

图片

用t他的组成部分:

import 'dart:math';

import 'package:flutter/material.dart';

class CircularBorder extends StatelessWidget {

  final Color color;
  final double size;
  final double width;
  final Widget icon;

  const CircularBorder({Key key, this.color = Colors.blue, this.size = 70, this.width = 7.0, this.icon}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      height: size,
      width: size,
      alignment: Alignment.center,
      child: Stack(
        alignment: Alignment.center,
        children: <Widget>[
          icon == null ? Container() : icon,
          CustomPaint(
            size: Size(size, size),
            foregroundPainter: new MyPainter(
                completeColor: color,
                width: width),
          ),
        ],
      ),
    );
  }
}

class MyPainter extends CustomPainter {
  Color lineColor =  Colors.transparent;
  Color completeColor;
  double width;
  MyPainter(
      { this.completeColor, this.width});
  @override
  void paint(Canvas canvas, Size size) {
    Paint complete = new Paint()
      ..color = completeColor
      ..strokeCap = StrokeCap.round
      ..style = PaintingStyle.stroke
      ..strokeWidth = width;

    Offset center = new Offset(size.width / 2, size.height / 2);
    double radius = min(size.width / 2, size.height / 2);
    var percent = (size.width *0.001) / 2;

    double arcAngle = 2 * pi * percent;
    print("$radius - radius");
    print("$arcAngle - arcAngle");
    print("${radius / arcAngle} - divider");

    for (var i = 0; i < 8; i++) {
      var init = (-pi / 2)*(i/2);

      canvas.drawArc(new Rect.fromCircle(center: center, radius: radius),
          init, arcAngle, false, complete);
    }


  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    return true;
  }
}

使用情况:

CircularBorder(
          width: 6,
          size: 55,
          color: Colors.grey,
          icon: Icon(Icons.access_alarm, color: Colors.grey),
        ),

这篇关于如何给“虚线边框”打分扑扑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆