Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter How to create Card with background Image?

Tags:

flutter

dart

I'm trying to create a Card with an Image as a background. The problem is, the Image overflows the Card, so the Corners of the don't show up.

I need to either set the Image as a background of the card or set the cards overflow behavior to no overflow. But I couldn't find any properties for that.

Here is my Card:

Widget _buildProgrammCard() {   return Container(     height: 250,     child: Card(       child: Image.asset(         'assets/push.jpg',         fit: BoxFit.cover,       ),       shape: RoundedRectangleBorder(         borderRadius: BorderRadius.circular(10.0),       ),       elevation: 5,       margin: EdgeInsets.all(10),     ),   ); 

And it looks like this:

enter image description here

enter image description here

like image 396
Jonas Avatar asked Dec 20 '18 10:12

Jonas


People also ask

How do you create a card in flutter?

Card creation in Flutter is very simple. We just need to call the card constructor and then pass a widget as child property for displaying the content and action inside the card. See the below code of simple card creation: return Card(


2 Answers

Other Way Without using - ClipRRect Widget - is To set semanticContainer: true, of Card Widget.

Example Code as Below:

Card(           semanticContainer: true,           clipBehavior: Clip.antiAliasWithSaveLayer,           child: Image.network(             'https://placeimg.com/640/480/any',             fit: BoxFit.fill,           ),           shape: RoundedRectangleBorder(             borderRadius: BorderRadius.circular(10.0),           ),           elevation: 5,           margin: EdgeInsets.all(10),         ), 

Output:

enter image description here

like image 119
anmol.majhail Avatar answered Sep 19 '22 01:09

anmol.majhail


You can wrap your image in ClipRRect

ClipRRect(   borderRadius: BorderRadius.vertical(top: Radius.circular(10.0)),   child: Image.network(...), ) 
like image 37
Andrey Turkovsky Avatar answered Sep 17 '22 01:09

Andrey Turkovsky