如何在TextButton中添加两种颜色?

问题描述 投票:0回答:1

如何在

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"),
                )),
flutter dart button
1个回答
0
投票

您可以尝试用容器包裹按钮,并使用线性渐变让容器为您想要的颜色设置颜色,并使按钮颜色为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: () {},
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.