How to add gradient color in the background of a card ? Should I reproduce this card with a container and a box decoration or is there another simple way ?
            Asked
            
        
        
            Active
            
        
            Viewed 1.3k times
        
    5 Answers
19
            
            
        Try below code hope it help to you in below answer change Color your need.
         Card(
            child: Container(
              height: 50,
              width: 150,
              decoration: BoxDecoration(
                gradient: LinearGradient(
                  colors: [
                    Colors.yellow,
                    Colors.orangeAccent,
                    Colors.yellow.shade300,
                  ],
                  begin: Alignment.topLeft,
                  end: Alignment.bottomRight,
                ),
              ),
              child: Container(), //declare your widget here
            ),
          ),
If you are gradient background to card or gradient border to card try below code
  Container(
        
          height: 50,
          width: 150,
          decoration: BoxDecoration(
            gradient: LinearGradient(
              colors: [
                Colors.yellow,
                Colors.orangeAccent,
                Colors.yellow.shade300,
              ],
              begin: Alignment.topLeft,
              end: Alignment.bottomRight,
            ),
          ),
        child:Card(
          color:Colors.white,
          child: Container(), //declare your widget here
        ),
      ),
        Ravindra S. Patil
        
- 11,757
 - 3
 - 13
 - 40
 
- 
                    
 - 
                    
 - 
                    Refer my updated answer, one thing forgot black color of updated image try updated code hope it's helpful to you – Ravindra S. Patil Aug 20 '21 at 07:34
 - 
                    
 - 
                    
 - 
                    
 - 
                    
 - 
                    1Add `clipBehavior: Clip.antiAlias` to your `Card` widget if you want the gradient to be clipped to the card shape (by default it will spill outside of the card rounded edges) – Jonathan Ellis Feb 01 '23 at 15:19
 
1
            
            
        I know it's a bit late, but you can try this to achieve a card gradient with border radius
return Container(
  decoration: BoxDecoration(
    borderRadius: BorderRadius.circular(12),
    boxShadow: [
      BoxShadow(
        color: Colors.black38,
        blurRadius: 3.0,
        spreadRadius: 0.0,
        offset: Offset(1.0, 1.0),
      )
    ],
    gradient: LinearGradient(
      colors: [startColor, endColor],
      begin: Alignment.bottomLeft,
      end: Alignment.topRight,
    ),
  ),
  child: Padding(
    padding: const EdgeInsets.all(12),
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        const SizedBox(height: 6),
        TextWidget(
          title,
          typographyToken: TypographyToken.text14SemiBold,
          color: Colors.white,
        ),
        const SizedBox(height: 8),
        TextWidget(
          "$pendingCount Pending Request",
          typographyToken: TypographyToken.text10,
          color: Colors.white,
        ),
        const SizedBox(height: 6),
      ],
    ),
  ),
);
Result :
        dugoymasta
        
- 11
 - 2
 
0
            
            
        This is a sample that I tried just now. Works fine for me.
Container(
            decoration: BoxDecoration(
                gradient: LinearGradient(
                    colors: [Colors.black, Colors.white],
                    begin: Alignment.topLeft,
                    end: Alignment.bottomRight)),
          )
        Filipe Piletti Plucenio
        
- 704
 - 10
 - 25
 
- 
                    
 - 
                    Thx, this is the best alternative I had, but you must also add circle border and an InkWell widget to do it like a card. I will do this if there is no other solution.. – Chloé Aug 20 '21 at 07:29
 
0
            
            
        Another way and probably the best in my opinion:
  Container(
                decoration: BoxDecoration(
                  gradient: LinearGradient(
                    begin: Alignment.centerRight,
                    end: Alignment.center,
                    colors: [Colors.deepOrangeAccent, Colors.orange],
                  ),
                ),
                width: 300,
                height: 300,
                child: Card(
                  color: Colors.transparent,
                ),
              ),
Output:
        darkShader
        
- 1
 - 2
 
-1
            
            
        Card(
        shadowColor: tabColorAmber,
        elevation: 10,
        child: Container(
          decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(12),
              gradient: LinearGradient(colors: [
                Colors.orangeAccent,
                Colors.orangeAccent,
                Colors.yellow.shade100,
              ])),
          width: double.infinity,
          height: 140,
        ),
      ),
        Paulo Borini
        
- 1
 - 1
 
- 
                    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 07 '22 at 20:51
 

