Flutter-如何在左上方创建带有标签的卡片?

时间:2019-09-10 05:17:54

标签: flutter flutter-layout

我想创建这样的东西:

enter image description here

但是我不知道如何创建与卡片匹配的圆形标签(绿色)。

2 个答案:

答案 0 :(得分:2)

enter image description here

SizedBox(
  width: 200,
  height: 200,
  child: Card(
    elevation: 12,
    shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
    child: Stack(
      children: <Widget>[
        Align(
          child: Image.asset(
            "your_image",
            width: 150,
            height: 100,
            fit: BoxFit.cover,
          ),
        ),
        Positioned(
          top: 0,
          child: Container(
            padding: EdgeInsets.symmetric(vertical: 4, horizontal: 6),
            decoration: BoxDecoration(
                color: Colors.green,
                borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(8),
                  bottomRight: Radius.circular(8),
                ) // green shaped
            ),
            child: Text("CHOCOLATE"),
          ),
        )
      ],
    ),
  ),
)

答案 1 :(得分:1)

使用Stack小部件,然后在其中添加卡片。

现在使用下面的代码添加您的green视图

Positioned(
  left: 0.0,
  top: 0.0,
  child: Container(
    color: Colors.green,
    height: 150.0,
    width: 150.0,
  ),
)

现在将以下图案用于green小部件的圆角。 enter image description here

  

来自herehere的引用