Colors.transparent opacity make background color darker – Flutter

huangapple go评论73阅读模式
英文:

Colors.transparent opacity make background color darker - Flutter

问题

I want to set a gradient as a background color for my ElevatedButton.

So I did this:

Container(
  height: 100,
  width: 100,
  decoration: const BoxDecoration(
    gradient: LinearGradient(
      begin: Alignment.topRight,
      end: Alignment.bottomLeft,
      colors: [
        Color(0xFFFE1871),
        Color(0xFFFD0E38),
        Color(0xFFFF0205),
      ],
    ),
  ),
  child: ElevatedButton(
    style: ElevatedButton.styleFrom(
      backgroundColor: Colors.transparent,
    ),
    onPressed: () {},
    child: const Text(
      'S\'inscrire',
    ),
  ),
),

But the gradient's colors are darker than expected.

Here's what I want:

Colors.transparent opacity make background color darker – Flutter

Here's what I have:

Colors.transparent opacity make background color darker – Flutter

It seems like there is some default opacity with Colors.transparent.

How to fix it?

英文:

I want to set a gradient as a background color for my ElevatedButton.

So I did this :

Container(
            height: 100,
            width: 100,
            decoration: const BoxDecoration(
                gradient: LinearGradient(
              begin: Alignment.topRight,
              end: Alignment.bottomLeft,
              colors: [
                Color(0xFFFE1871),
                Color(0xFFFD0E38),
                Color(0xFFFF0205),
              ],
            )),
            child: ElevatedButton(
                style: ElevatedButton.styleFrom(
                    backgroundColor: Colors.transparent),
                onPressed: () {},
                child: const Text(
                  'S\'inscrire',
                )),
          ),

But the gradient's colors are darker than expected.

Here's what I want :

Colors.transparent opacity make background color darker – Flutter

Here's what I have :

Colors.transparent opacity make background color darker – Flutter

It seems like there is some default opacity with Colors.transparent.

How to fix it ?

答案1

得分: 2

Add shadowColor

style: ElevatedButton.styleFrom(
  backgroundColor: Colors.transparent,
  shadowColor: Colors.transparent,
),
英文:

Add shadowColor

style: ElevatedButton.styleFrom(
  backgroundColor: Colors.transparent,
  shadowColor: Colors.transparent,
),

答案2

得分: 1

以下是您要翻译的部分:

ElevatedButton.styleFrom(
    backgroundColor: Colors.transparent,
    shadowColor: Colors.transparent,
)

"shadowColor" 翻译为 "阴影颜色"。

英文:

it's shadowColor

ElevatedButton.styleFrom(
                    backgroundColor: Colors.transparent,
                   shadowColor: Colors.transparent,                                                     
                )

its work for me below is the code and screenshot

 Container(
        height: 100,
        width: 100,
        decoration: const BoxDecoration(
            gradient: LinearGradient(
          begin: Alignment.topRight,
          end: Alignment.bottomLeft,
          colors: [
            Color(0xFFFE1871),
            Color(0xFFFD0E38),
            Color(0xFFFF0205),
           
          ],
        )),
        child: ElevatedButton(
            style: ElevatedButton.styleFrom(
                backgroundColor: Colors.transparent,
               shadowColor: Colors.transparent,                                                     
            ),
            onPressed: () {},
            child: const Text(
              'S\'inscrire',
            )),
      )

Colors.transparent opacity make background color darker – Flutter

答案3

得分: 0

我知道这可能不是最佳解决方案,但你可以尝试这样做:

style: ElevatedButton.styleFrom(
backgroundColor: Colors.white.withOpacity(0),
shadowColor: Colors.white.withOpacity(0), ),
英文:

I know this might not be the best solution but you can try with this

style: ElevatedButton.styleFrom(
backgroundColor: Colors.white.withOpacity(0),
shadowColor: Colors.white.withOpacity(0), ),

huangapple
  • 本文由 发表于 2023年5月11日 17:34:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76226175.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定