Skip to main content

Cards

Card components are versatile containers for grouping related content and actions. They support headers, footers, images, and various styling options.

ChromiaCard

A customizable card component that follows the Chromia design system.

Basic Usage

ChromiaCard(
  child: Padding(
    padding: EdgeInsets.all(16),
    child: Text('Card content'),
  ),
)

Parameters

child
Widget
required
The main content of the card.
header
Widget?
Optional header widget displayed at the top of the card.
Optional footer widget displayed at the bottom of the card.
image
Widget?
Optional image widget.
imagePosition
CardImagePosition
default:"CardImagePosition.top"
Position of the image relative to content. Options: top, bottom.
onTap
VoidCallback?
Callback when the card is tapped. Makes the card interactive with hover effects.
padding
EdgeInsetsGeometry?
Padding for the main content. Defaults to theme spacing.
headerPadding
EdgeInsetsGeometry?
Padding for the header section.
Padding for the footer section.
margin
EdgeInsetsGeometry?
Margin around the card.
elevation
double
default:"1"
Elevation of the card (0-9). Controls the shadow depth.
borderRadius
BorderRadius?
Border radius of the card. Defaults to theme radius.
backgroundColor
Color?
Background color of the card.
borderColor
Color?
Border color. If provided, adds a border to the card.
borderWidth
double?
Border width when borderColor is specified.
width
double?
Width of the card.
height
double?
Height of the card.
clipBehavior
Clip
default:"Clip.antiAlias"
Clip behavior for the card content.

Examples

Simple Card

ChromiaCard(
  child: Padding(
    padding: EdgeInsets.all(16),
    child: Text('Simple card content'),
  ),
)
ChromiaCard(
  header: Text('Card Title'),
  footer: Row(
    mainAxisAlignment: MainAxisAlignment.end,
    children: [
      TextButton(
        onPressed: () {},
        child: Text('Cancel'),
      ),
      SizedBox(width: 8),
      ElevatedButton(
        onPressed: () {},
        child: Text('Save'),
      ),
    ],
  ),
  child: Text('Main card content here'),
)

Card with Image

ChromiaCard(
  image: Image.network(
    'https://example.com/image.jpg',
    height: 200,
    fit: BoxFit.cover,
  ),
  header: Text('Image Card'),
  child: Text('Card with a cover image on top'),
)

Interactive Card

ChromiaCard(
  onTap: () => print('Card tapped'),
  elevation: 2,
  child: Padding(
    padding: EdgeInsets.all(16),
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text('Clickable Card', style: TextStyle(fontWeight: FontWeight.bold)),
        SizedBox(height: 8),
        Text('Tap me to see the hover effect'),
      ],
    ),
  ),
)

Card with Custom Styling

ChromiaCard(
  elevation: 4,
  borderRadius: BorderRadius.circular(20),
  backgroundColor: Colors.blue.shade50,
  borderColor: Colors.blue,
  borderWidth: 2,
  child: Padding(
    padding: EdgeInsets.all(24),
    child: Text('Custom styled card'),
  ),
)

Fixed Size Card

ChromiaCard(
  width: 300,
  height: 200,
  child: Center(
    child: Text('Fixed size card'),
  ),
)

Card with Bottom Image

ChromiaCard(
  header: Text('Header'),
  child: Text('Content above the image'),
  image: Image.network(
    'https://example.com/image.jpg',
    height: 150,
    fit: BoxFit.cover,
  ),
  imagePosition: CardImagePosition.bottom,
)

ChromiaListTileCard

A specialized card for displaying list items with leading, trailing, title, and subtitle.

Parameters

title
Widget
required
The primary content (main text).
subtitle
Widget?
Additional content displayed below the title.
leading
Widget?
A widget to display before the title (e.g., icon, avatar).
trailing
Widget?
A widget to display after the title (e.g., icon, chevron).
onTap
VoidCallback?
Callback when the card is tapped.
padding
EdgeInsetsGeometry?
Padding around the content. Defaults to theme spacing.
elevation
double
default:"1"
Elevation of the card.

Examples

Simple List Tile Card

ChromiaListTileCard(
  title: Text('Title'),
  subtitle: Text('Subtitle'),
  leading: Icon(Icons.star),
  trailing: Icon(Icons.arrow_forward),
  onTap: () => print('Tapped'),
)

User List Item

ChromiaListTileCard(
  leading: ChromiaAvatar(
    imageUrl: 'https://example.com/user.jpg',
  ),
  title: Text('John Doe'),
  subtitle: Text('[email protected]'),
  trailing: Icon(Icons.chevron_right),
  onTap: () => viewUserProfile(),
)

Settings List Item

ChromiaListTileCard(
  leading: Icon(Icons.settings, color: Colors.blue),
  title: Text('Settings'),
  subtitle: Text('App preferences and options'),
  trailing: Icon(Icons.arrow_forward_ios, size: 16),
  onTap: () => navigateToSettings(),
)

Notification Card

ChromiaListTileCard(
  leading: Container(
    padding: EdgeInsets.all(8),
    decoration: BoxDecoration(
      color: Colors.blue.shade100,
      shape: BoxShape.circle,
    ),
    child: Icon(Icons.notifications, color: Colors.blue),
  ),
  title: Text('New notification'),
  subtitle: Text('You have a new message'),
  trailing: Text(
    '2m ago',
    style: TextStyle(fontSize: 12, color: Colors.grey),
  ),
  onTap: () => viewNotification(),
)

Task List Item

ChromiaListTileCard(
  leading: Checkbox(
    value: isCompleted,
    onChanged: (value) => toggleComplete(),
  ),
  title: Text(
    'Complete documentation',
    style: TextStyle(
      decoration: isCompleted ? TextDecoration.lineThrough : null,
    ),
  ),
  subtitle: Text('Due: Tomorrow'),
  trailing: IconButton(
    icon: Icon(Icons.more_vert),
    onPressed: () => showOptions(),
  ),
)

Product Card

ChromiaListTileCard(
  leading: Image.network(
    'https://example.com/product.jpg',
    width: 50,
    height: 50,
    fit: BoxFit.cover,
  ),
  title: Text('Product Name'),
  subtitle: Text(r'$29.99'),
  trailing: ChromiaButton(
    onPressed: () => addToCart(),
    child: Text('Add'),
  ),
  elevation: 2,
)

Enums

CardImagePosition

  • top - Image at the top of the card
  • bottom - Image at the bottom of the card

Build docs developers (and LLMs) love