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:
In this button grey part is container background color. Then I added a image in this container. Now the red color should dynamic with height received from server. But I am not getting a correct way how I can do it.
You can easily achieve this with container and linear gradient. Pass in the colors as gradient and define appropriate stops at the required percentages.
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,
),
),
);
}
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With