I’m using flutter and i can’t put a linear gradient overlay to my image.
I tried some solutions but no one works, can someone explain to me how can i get the result that i show in the image? The image is from internet.
Thanks
This is what i want
2
you can add a linear gradient overlay to an image using the Stack widget to overlay widgets on top of each other.
Here is example for that
Stack( children: <Widget>[ Image.network( 'https://example.com/your-image.jpg', width: double.infinity, height: double.infinity, fit: BoxFit.cover, ), Container( width: double.infinity, height: double.infinity, decoration: BoxDecoration( gradient: LinearGradient( begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [ Colors.transparent, Colors.black.withOpacity(0.6), ], ), ), ), ], ),
You can use ShaderMask widget to apply a mask generated by a LinearGradient shader to your image:
ShaderMask( shader: LinearGradient( begin: Alignment.topLeft, end: Alignment.bottomRight, colors: [Colors.black.withOpacity(0.5), Colors.transparent], ).createShader(Rect.fromLTRB(0, 0, double.infinity, double.infinity)), child: Image.network(imageUrl), );
Click here to cancel reply.
2
Answers
you can add a linear gradient overlay to an image using the Stack widget to overlay widgets on top of each other.
Here is example for that
You can use ShaderMask widget to apply a mask generated by a LinearGradient shader to your image: