如何在卡片中添加渐变颜色?

Chl*_*loé 10 colors flutter card

如何在卡片背景中添加渐变色?我应该用容器和盒子装饰复制这张卡片还是有其他简单的方法?

Rav*_*til 20

尝试下面的代码希望它对您在下面的答案中有所帮助,改变您需要的颜色。

         Card(
            child: Container(
              height: 50,
              width: 150,
              decoration: BoxDecoration(
                gradient: LinearGradient(
                  colors: [
                    Colors.yellow,
                    Colors.orangeAccent,
                    Colors.yellow.shade300,
                  ],
                  begin: Alignment.topLeft,
                  end: Alignment.bottomRight,
                ),
              ),
              child: Container(), //declare your widget here
            ),
          ),
Run Code Online (Sandbox Code Playgroud)

你的卡片看起来像->在此输入图像描述

如果您是卡片的渐变背景或卡片的渐变边框,请尝试以下代码

  Container(
        
          height: 50,
          width: 150,
          decoration: BoxDecoration(
            gradient: LinearGradient(
              colors: [
                Colors.yellow,
                Colors.orangeAccent,
                Colors.yellow.shade300,
              ],
              begin: Alignment.topLeft,
              end: Alignment.bottomRight,
            ),
          ),
        child:Card(
          color:Colors.white,
          child: Container(), //declare your widget here
        ),
      ),
Run Code Online (Sandbox Code Playgroud)

你的屏幕就像 ->在此输入图像描述

  • 如果您希望将渐变剪切到卡片形状,请将“clipBehavior: Clip.antiAlias”添加到“Card”小部件中(默认情况下,它将溢出到卡片圆角边缘之外) (2认同)

Fil*_*nio 0

这是我刚刚尝试过的示例。对我来说效果很好。

Container(
            decoration: BoxDecoration(
                gradient: LinearGradient(
                    colors: [Colors.black, Colors.white],
                    begin: Alignment.topLeft,
                    end: Alignment.bottomRight)),
          )
Run Code Online (Sandbox Code Playgroud)