flutter making image with rounded corners and adding bottom text
use black for gradients and white for text, otherwise some pics are
lighter in the bottom and your text will not be seen
we use stack to overlay gradient and text
Container - optional to set height and width
Cliprrect - for rounder corners
child: Stack - child of Cliprrect
[ // children of stack
image
Positioned - for gradient and text
]
flutter code - pass a valid pic url to addImage
Container(
height: 200, width: 200, ///////////optional
margin: EdgeInsets.all(9.0),
child: ClipRRect( //////////rounded corners
borderRadius: BorderRadius.circular(15.0),
child: Stack(children: [ //////////overlay gradient and text
addImage(picURL),
Positioned(bottom: 0, left: 0, right: 0, child: containerWithGradAndText()),
],),//stack, widget children
),//cliprrect
),//container
),//scaffold
);}//material app, build
//////////////functions to not pollute above
//////////// fill container with image
Widget addImage(String pic){return Positioned.fill(child: Image.network('$pic', fit: BoxFit.cover));}
//////////////// add bottom black gradient to image
LinearGradient myGradient() {return LinearGradient( begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [Colors.black26, Colors.black],);}
/////////////////// add text to image
Widget addText(String s){return Text('$s',style:TextStyle(color:Colors.white),);}
//////////////////// container with gradient and text
Widget containerWithGradAndText(){return
Container(
padding: EdgeInsets.all(9.0),
decoration: BoxDecoration(gradient: myGradient()),
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [addText('line1'), addText('line2')]));}