10

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 ?

Chloé
  • 331
  • 1
  • 5
  • 14

5 Answers5

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
            ),
          ),

Your Card look like-> enter image description 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
        ),
      ),

Your Screen like -> enter image description here

Ravindra S. Patil
  • 11,757
  • 3
  • 13
  • 40
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 :

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)),
          )
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:

Click here to view

-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,
        ),
      ),

Example

  • 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