首页 > 解决方案 > 折卡效果——Flutter

问题描述

我想做一个如下图的效果,我在 Stack 中添加了一个 Card 和一个 Container 来显示上面的徽章。但我不确定徽章的左上角使用什么或哪个小部件。

在此处输入图像描述

谁能指导我如何达到这种效果。

我现在的状态: 在此处输入图像描述

标签: flutterflutter-layout

解决方案


将 aCustomPaint用于三角形部分并与您的文本合成 aRow

class TrianglePainter extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    Paint paint = Paint()
      ..color = Colors.grey
      ..strokeWidth = 2.0;
    Path path = Path();
    path.moveTo(0.0, size.height);
    path.lineTo(size.width, 0.0);
    path.lineTo(size.width, size.height);
    canvas.drawPath(path, paint);
  }

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

在你的Row

Row(
         crossAxisAlignment: CrossAxisAlignment.start,
         children: <Widget>[
           SizedBox(
             height: 8.0,
             width: 5.0,
             child: CustomPaint(
               painter: TrianglePainter(),
             ),
           ),
           Container(
             decoration: BoxDecoration(
                 color: Colors.red,
                 borderRadius: BorderRadius.only(
                     topRight: Radius.circular(6.0),
                     bottomLeft: Radius.circular(6.0))),
             width: 120.0,
             height: 30.0,
             child: Center(
               child: Text(
                 'Customer Replay',
                style: TextStyle(color: Colors.white),
               ),
             ),
           ),
         ],
        ),

在此处输入图像描述


推荐阅读