如何在
TextButton
中添加两种颜色? 我们可以在Container中添加LinearGradient
,但是TextButton呢?
TextButton.icon(
style: TextButton.styleFrom(
backgroundColor: Colors.blue,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(15.0), // Set the rounded corners
), // Set the background color here
),
onPressed: () {},
label: ListTile(
title: Text("Smart Lock"),
subtitle: Text("For you to lock and unlock door"),
)),
您可以尝试用容器包裹按钮,并使用线性渐变让容器为您想要的颜色设置颜色,并使按钮颜色为Colors.transparent。
示例代码
Container(
decoration: BoxDecoration(
**gradient: LinearGradient(
colors: [Colors.blue, Colors.purple],
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),**
),
child: TextButton.icon(
style: TextButton.styleFrom(
**backgroundColor: Colors.transparent,**
),
onPressed: () {},