159

I have developed an app with GridView on Flutter. GridView items are Card and the default card shape is Rectangle with a radius of 4.

I know there is shape property for Card Widget and it takes ShapeBorder class but I am unable to find how to use ShapeBorder class and customize my cards in GridView.

How do I go about this?

0

6 Answers 6

333

You can use it this way

enter image description here

Card(
  shape: RoundedRectangleBorder(
    borderRadius: BorderRadius.circular(15.0),
  ),
  child: Text(
    'Card with circular border',
    textScaleFactor: 1.2,
  ),
),
Card(
  shape: BeveledRectangleBorder(
    borderRadius: BorderRadius.circular(10.0),
  ),
  child: Text(
    'Card with Beveled border',
    textScaleFactor: 1.2,
  ),
),
Card(
  shape: StadiumBorder(
  side: BorderSide(
    color: Colors.black,
    width: 2.0,
  ),
),
  child: Text(
    'Card with Stadium border',
    textScaleFactor: 1.2,
  ),
),
Sign up to request clarification or add additional context in comments.

5 Comments

Using the RoundedRectangleBorder I also able to get a rounded shape to the Card. But an Image inside it - does not cropped by the Card's rounded image shape. How we can do that? Thanks!
@SantanuKarar You wrap the image in ClipRRect() - docs.flutter.io/flutter/widgets/ClipRRect-class.html
@aziza how to change border color?
This answer was super useful to understand how to add borders and colors to chip as well!
after using Roundedrectangle border with circular it only round bottom card side not upper card side
91

When Card I always use RoundedRectangleBorder.

Card(
  color: Colors.grey[900],
  shape: RoundedRectangleBorder(
    side: BorderSide(color: Colors.white70, width: 1),
    borderRadius: BorderRadius.circular(10),
  ),
  margin: EdgeInsets.all(20.0),
  child: Container(
    child: Column(
        children: <Widget>[
        ListTile(
            title: Text(
            'example',
            style: TextStyle(fontSize: 18, color: Colors.white),
            ),
        ),
        ],
    ),
  ),
),

2 Comments

Remember to add elevation: 0 to the Card widget to remove the default shadow.
how can i apply only a single border to the card , like only right border
35

You can also customize the card theme globally with ThemeData.cardTheme:

MaterialApp(
  title: 'savvy',
  theme: ThemeData(
    cardTheme: CardTheme(
      shape: RoundedRectangleBorder(
        borderRadius: const BorderRadius.all(
          Radius.circular(8.0),
        ),
      ),
    ),
    // ...

2 Comments

yes this is modular approach. if you have same style card throughout the app.
that should be the recommended way!
18

An Alternative Solution to the above

Card(
  shape: RoundedRectangleBorder(
     borderRadius: BorderRadius.only(topLeft: Radius.circular(20), topRight: Radius.circular(20))),
  color: Colors.white,
  child: ...
)

You can use BorderRadius.only() to customize the corners you wish to manage.

Comments

12

A Better way to customise Card Radius ( Also other options ) is to set theme for Card globally. So that you can use same style for Card througout the entire app. You can use this method for many other widget also.

For Card Theme you can use ThemeData.cardTheme

MaterialApp(
 title: 'MySampleApp',
 theme: ThemeData(
   cardTheme: CardTheme(
     shape: RoundedRectangleBorder(
       borderRadius: BorderRadius.all(
         Radius.circular(16.0),
       ),
     ),
   ),
// ............
// ............

1 Comment

U can also use the short-hand BorderRadius.circular(8) instead of BorderRadius.all(Radius.circular(5.0)).
1

You can shape like this in card custom circle with icons

Card(
  elevation: 20,
  shape: RoundedRectangleBorder(
    borderRadius: BorderRadius.circular(100),
  ),
  child: const Icon(
    Icons.list,
    size: 92,
  ),
)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.