【问题标题】:How do I add color gradient to Card in flutter如何在颤动中向卡片添加颜色渐变
【发布时间】:2021-12-31 16:16:08
【问题描述】:

我想在 Flutter 中为卡片添加颜色渐变,尝试了几种使用 Containerdecoration 的方法,但无法让整个代码正常工作。

这是当前的工作代码,我想用渐变替换第 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>[],
                    ),
                ),
                ),
            ]
          )
      ),
   );

我尝试了这篇文章 here 中给出的建议,但无法将其与我的代码正确集成。

【问题讨论】:

  • 参考我的回答here希望对你有帮助。

标签: flutter colors linear-gradients


【解决方案1】:

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")],
                          ),
                        ),
                      ),
                    ])),
              ),
            ),

【讨论】:

  • 谢谢你!正是我需要的!
猜你喜欢
  • 2021-10-21
  • 2020-05-01
  • 1970-01-01
  • 2021-11-28
  • 1970-01-01
  • 1970-01-01
  • 2021-11-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多