【问题标题】:How can I add text to a card that has been filled with an image for its background?如何将文本添加到已填充图像作为背景的卡片?
【发布时间】:2018-12-26 16:17:09
【问题描述】:

我在我的主页上添加了一张卡片并使用了“Image.asset”来为其提供背景图片。我现在想在这张卡片上添加一些文字,但一直不知道怎么做...任何帮助将不胜感激!

Card(  
    semanticContainer: true,  
    clipBehavior: Clip.antiAliasWithSaveLayer,  
        child: Image.asset(  
            'assets/images/image.png',  
            fit: BoxFit.cover,  
        ),  
            shape: RoundedRectangleBorder(  
            borderRadius: BorderRadius.circular(10.0),  
        ),  
            elevation: 5,  
            margin: EdgeInsets.symmetric(vertical: 9, horizontal: 10),  
),  

以上是我目前拥有的代码(没有我想添加的任何文本)。

【问题讨论】:

    标签: dart flutter


    【解决方案1】:

    例如实现Stack

    Stack(
        children: <Widget>[
          Card(
            semanticContainer: true,
            clipBehavior: Clip.antiAliasWithSaveLayer,
            child: Image.network(
              'https://source.unsplash.com/WLUHO9A_xik/900x900',
              fit: BoxFit.cover,
            ),
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(10.0),
            ),
            elevation: 5,
            margin: EdgeInsets.symmetric(vertical: 9, horizontal: 10),
          ),
          Positioned(
            right: 0.0,
            bottom: 0.0,
            child: Text('Example'),
          )
        ],
      ),
    

    【讨论】:

    • 非常感谢您的回复,这正是我想要的!
    • 很抱歉一直在问问题,但作为一个附加问题,我有什么办法可以改变这张卡片的高度吗?
    • 用容器包裹图片,可以设置
    【解决方案2】:

    结帐StackContainer 并带有装饰。

    您可以将小部件与Stack 重叠。

    您可以将AssetImage 设置为BoxDecorationContainer

    【讨论】:

      猜你喜欢
      • 2020-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-29
      • 1970-01-01
      • 1970-01-01
      • 2019-06-17
      • 2021-12-23
      相关资源
      最近更新 更多