I am trying to make a container that has LinearGradient as its background but with these constraints:
- The linear gradient is from left to right
- The linear gradient color only covers the half top of the container
As shown in the image below, what I want to build is this.
This is what I have tried:
...
Widget build(context) {
return Container( // 1. Outer container (black border box in image)
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [//color1, //color2],
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),
),
child: Center(
child: Container( // 2. Inner container (colored white in image)
// some padding and decoration for border-radius
),
)
)
}
...
But what it does is the gradient color covering all of the outer container (what I want is only half the top of the outer container). Is it possible to do this? If yes, how to do it?
2
Answers
Positioned within a Stack to achieve the desired gradient effect
Try this