如何在 flutter 中向 Card 添加颜色渐变
How do I add color gradient to Card in flutter
我想在 Flutter 中为卡片添加颜色渐变,尝试了 Container
和 decoration
的几种方法,但无法让整个代码正常工作。
这是当前的工作代码,我想用渐变替换第 3 行:
return new Card(
elevation: 5.0,
color: color.orangeAccent, //I want to replace this color with a gradient
child: Padding(
padding: new EdgeInsets.all(15.0),
child: Column(
children: <Widget>[
InkWell(
onTap: () {},
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[],
),
),
),
]
)
),
);
我试过 post here 中给出的建议,但无法将其与我的代码正确集成。
用 Container
包装您的列并使用渐变色装饰
Card(
elevation: 5.0,
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.green,
Colors.blue,
],
begin: const FractionalOffset(0.0, 0.0),
end: const FractionalOffset(1.0, 0.0),
stops: [0.0, 1.0],
tileMode: TileMode.clamp),
),
child: Padding(
padding: new EdgeInsets.all(15.0),
child: Column(children: <Widget>[
InkWell(
onTap: () {},
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[Text("Test")],
),
),
),
])),
),
),
我想在 Flutter 中为卡片添加颜色渐变,尝试了 Container
和 decoration
的几种方法,但无法让整个代码正常工作。
这是当前的工作代码,我想用渐变替换第 3 行:
return new Card(
elevation: 5.0,
color: color.orangeAccent, //I want to replace this color with a gradient
child: Padding(
padding: new EdgeInsets.all(15.0),
child: Column(
children: <Widget>[
InkWell(
onTap: () {},
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[],
),
),
),
]
)
),
);
我试过 post here 中给出的建议,但无法将其与我的代码正确集成。
用 Container
包装您的列并使用渐变色装饰
Card(
elevation: 5.0,
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.green,
Colors.blue,
],
begin: const FractionalOffset(0.0, 0.0),
end: const FractionalOffset(1.0, 0.0),
stops: [0.0, 1.0],
tileMode: TileMode.clamp),
),
child: Padding(
padding: new EdgeInsets.all(15.0),
child: Column(children: <Widget>[
InkWell(
onTap: () {},
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[Text("Test")],
),
),
),
])),
),
),