【问题标题】:Folded card effect - Flutter折卡效果——Flutter
【发布时间】:2019-05-11 14:43:10
【问题描述】:

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

谁能指导我如何实现这种效果。

我现在的状态:

【问题讨论】:

  • 你可以使用CustomPainter
  • 我会说只是画一个三角形

标签: flutter flutter-layout


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-09
    • 1970-01-01
    • 2019-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多