【问题标题】:How can I add a text and a bakground-image in a card?如何在卡片中添加文本和背景图像?
【发布时间】:2020-08-09 10:23:48
【问题描述】:

我尝试在卡片中的图片上添加文字。我需要背景中的图片和前景中的文本。当我点击它时,它应该会切换到另一个屏幕,但到目前为止我还没有编写代码。这是我尝试在图片上“覆盖”文字的代码,但出现错误。有谁能够帮我?提前致谢。

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

【问题讨论】:

    标签: flutter layout flutter-layout


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-29
      • 2021-12-23
      • 2022-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多