I am trying to achieve a custom design dynamically from my button. I have designed this button from a Container with InkWell. But I am not getting a correct way how I can set 2 different colours to this button based on received values from my API.
For reference here is the button:
在这个按钮中灰色部分是容器背景色。然后我在这个容器中添加了一个图像。现在红色应该随着从服务器接收到的高度而动态变化。
但我没有找到正确的方法。
您可以使用容器和线性渐变轻松实现这一点。将颜色作为渐变传递,并以所需的百分比定义适当的停止点。
Example:
@override
Widget build(BuildContext context) {
final Color background = Colors.grey;
final Color fill = Colors.redAccent;
final List<Color> gradient = [
background,
background,
fill,
fill,
];
final double fillPercent = 56.23; // fills 56.23% for container from bottom
final double fillStop = (100 - fillPercent) / 100;
final List<double> stops = [0.0, fillStop, fillStop, 1.0];
return Container(
child: Icon(Icons.forward),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: gradient,
stops: stops,
end: Alignment.bottomCenter,
begin: Alignment.topCenter,
),
),
);
}
希望这可以帮助!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)