【发布时间】:2021-10-21 10:03:22
【问题描述】:
如何在卡片背景中添加渐变色?我应该用容器和盒子装饰来复制这张卡片还是有其他简单的方法?
【问题讨论】:
-
你能添加你的代码sn-p吗?它可以通过使用容器来完成
如何在卡片背景中添加渐变色?我应该用容器和盒子装饰来复制这张卡片还是有其他简单的方法?
【问题讨论】:
这是我刚刚尝试的示例。适合我。
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.black, Colors.white],
begin: Alignment.topLeft,
end: Alignment.bottomRight)),
)
【讨论】:
试试下面的代码希望它在下面的答案中对你有所帮助改变你需要的颜色。
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
),
),
如果你是渐变背景卡试试下面的代码
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
),
),
【讨论】:
另一种方式,可能是我认为最好的方式:
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.centerRight,
end: Alignment.center,
colors: [Colors.deepOrangeAccent, Colors.orange],
),
),
width: 300,
height: 300,
child: Card(
color: Colors.transparent,
),
),
输出:
【讨论】: