折卡效果-颤振

时间:2018-12-10 16:47:37

标签: flutter flutter-layout

我想产生如下所示的效果,我在堆栈中添加了卡片和容器以显示上方的徽章。但是我不确定在徽章的左上角使用什么或哪个小部件。

enter image description here

任何人都可以指导我如何实现这种效果。

我当前的状态: enter image description here

1 个答案:

答案 0 :(得分:7)

对三角形部分使用CustomPaint,并在Row中与您的文字合成

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),
               ),
             ),
           ),
         ],
        ),

enter image description here