如何在卡片中添加文本和背景图像?

时间:2020-04-25 20:30:23

标签: flutter layout flutter-layout

我试图在卡片上的图片上写文字。我需要背景图片和前景文本。当我单击它时,它应该切换到另一个屏幕,但到目前为止我还没有编码。这是我尝试在图片“上方”制作文本的代码,但出现错误。有谁能够帮助我?预先感谢。

Card(
              semanticContainer: true,
              child: Image.asset(
                'images/Bild1.jpg',
                fit: BoxFit.fill,
              ),
                Text("test")
            ),

1 个答案:

答案 0 :(得分:0)

您必须使用Stack将文本定位在图像上方;您不能仅在卡片child下添加没有任何上下文的文本。尝试以下代码:

Card(
  semanticContainer: true,
  child: Stack(
    children: [
      Image.asset(
        'images/Bild1.jpg',
        fit: BoxFit.fill,
      ),
      Text("test"),
    ],
  ),
);