英文:
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:
Here's what I have:
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 :
Here's what I have :
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',
)),
)
答案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), ),
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论