简体   繁体   English

如何使用 flutter 中的 ShapeBorder Class 制作带有黑色实心圆形边框的自定义形状

[英]How to make custom shape with black solid rounded border using ShapeBorder Class in flutter

I want to have this mentioned below shape in flutter with black solid borders around it, I am new to flutter and I do not know much about ShapeBorder to create this kind of shape, please help me out, how to create this by using ShapeBorder, I have written some code below but it does not have any black border around it?我想在 flutter 中使用下面提到的形状,周围有黑色实心边框,我是 flutter 的新手,我对 ShapeBorder 不太了解如何创建这种形状,请帮助我,如何使用 ShapeBorder 创建这个,我在下面写了一些代码,但它周围没有任何黑色边框? please help me out, thanks in advance,请帮帮我,在此先感谢,

  import 'package:flutter/material.dart';
    class InfoDialog extends ShapeBorder {
      final bool usePadding;
    
      InfoDialog({this.usePadding = true});
    
      @override
      EdgeInsetsGeometry get dimensions => EdgeInsets.only(bottom: usePadding? 20 : 0);
    
      @override
      Path getInnerPath(Rect rect, {TextDirection textDirection}) => null;
    
      @override
      Path getOuterPath(Rect rect, {TextDirection textDirection}) {
        rect = Rect.fromPoints(rect.topLeft, rect.bottomRight - Offset(0, 13));
        return Path()
          ..addRRect(RRect.fromRectAndRadius(rect, Radius.circular(5)))
          ..moveTo(rect.bottomLeft.dx+40 , rect.bottomCenter.dy)
          ..relativeLineTo(5, 10)
          ..relativeLineTo(10, -10)
          ..close();
      }
    

      @override
      void paint(Canvas canvas, Rect rect, {TextDirection textDirection}) {


    Paint paint = new Paint()
      ..color = Colors.black
      ..style = PaintingStyle.stroke
      ..strokeWidth = 1;
    canvas.drawPath(getOuterPath(rect), paint);
}
    
      @override
      ShapeBorder scale(double t) => this;
    }

This is my output and want to make like second one这是我的 output 并且想做第二个

在此处输入图像描述

This is what I want to make, please look into it这是我想做的,请看一下

在此处输入代码

you can see this example and you can use flutter_custom_clippers: ^1.1.2 and easily make like this.你可以看到这个例子,你可以使用 flutter_custom_clippers: ^1.1.2 并轻松地制作这样的东西。 example: https://pub.dev/packages/flutter_custom_clippers/example示例: https://pub.dev/packages/flutter_custom_clippers/example

snapshot快照

Path getOuterPath(Rect rect, {TextDirection? textDirection}) {
rect = Rect.fromPoints(rect.topLeft, rect.bottomRight - Offset(0, 13));
Path p1 = Path()
  ..moveTo(rect.bottomLeft.dx + 40, rect.bottomCenter.dy)
  ..relativeLineTo(5, 10)
  ..relativeLineTo(10, -10)
  ..close();

Path p2 = Path()
  ..addRRect(RRect.fromRectAndRadius(rect, Radius.circular(5)))
  ..close();

return Path.combine(PathOperation.union, p1, p2);

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM