Cards
Loading preview
Starting the Flutter app
A Flutter cards gallery with elevated, outlined, gradient, and interactive card styles.
import 'package:flutter/material.dart';
class Cards extends StatelessWidget {
const Cards({super.key});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final scheme = theme.colorScheme;
return Scaffold(
appBar: AppBar(title: const Text('Cards')),
body: ListView(
padding: const EdgeInsets.all(16),
children: [
_label(context, 'Elevated'),
Card(
elevation: 3,
child: ListTile(
leading: const Icon(Icons.bolt),
title: const Text('Elevated card'),
subtitle: const Text('Casts a soft shadow above the surface.'),
),
),
const SizedBox(height: 16),
_label(context, 'Outlined'),
Card(
elevation: 0,
shape: RoundedRectangleBorder(
side: BorderSide(color: scheme.outlineVariant),
borderRadius: BorderRadius.circular(12),
),
child: const ListTile(
leading: Icon(Icons.crop_square),
title: Text('Outlined card'),
subtitle: Text('A hairline border, no shadow.'),
),
),
const SizedBox(height: 16),
_label(context, 'Gradient'),
Container(
height: 120,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [scheme.primary, scheme.tertiary],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.circular(16),
),
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Gradient card',
style: theme.textTheme.titleLarge?.copyWith(
color: Colors.white, fontWeight: FontWeight.bold)),
const Text('Great for highlights and hero stats.',
style: TextStyle(color: Colors.white70)),
],
),
),
const SizedBox(height: 16),
_label(context, 'Interactive'),
Card(
clipBehavior: Clip.antiAlias,
child: InkWell(
onTap: () => _showDemo(context, 'Tappable media card (demo)'),
child: Column(
children: [
Container(
height: 100,
color: scheme.secondaryContainer,
child: Icon(Icons.image,
size: 40, color: scheme.onSecondaryContainer),
),
Padding(
padding: const EdgeInsets.all(14),
child: Row(
children: [
const Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Tappable media card',
style:
TextStyle(fontWeight: FontWeight.w600)),
Text('With an ink ripple on tap.'),
],
),
),
const Icon(Icons.chevron_right),
],
),
),
],
),
),
),
],
),
);
}
Widget _label(BuildContext context, String text) {
return Padding(
padding: const EdgeInsets.only(bottom: 8),
child: Text(text.toUpperCase(),
style: Theme.of(context).textTheme.labelSmall?.copyWith(
letterSpacing: 1,
color: Theme.of(context).colorScheme.onSurfaceVariant)),
);
}
}
void _showDemo(BuildContext context, String message) {
ScaffoldMessenger.of(context)
..hideCurrentSnackBar()
..showSnackBar(SnackBar(content: Text(message)));
}
Add it to your project
Copies the Dart source into your app, so you own it. Flutter SDK only, no extra packages.
First time? Run dart pub global activate fluttertemplates_dev, or read the CLI guide.
How it works
Four variants sit in one stateless ListView, separated by _label headers. Elevated and outlined are Cards with different elevation and shape. The gradient one is actually a Container, so CardTheme won’t reach it and its white text is set by hand. The interactive card uses Clip.antiAlias to keep the InkWell ripple inside the corners, and its onTap shows a demo SnackBar.
Adapting it
- Lift a
Cardvariant into its own widget with title and subtitle parameters before reusing it. - Check
Colors.whitetext againstscheme.primaryandscheme.tertiaryin your theme, since it won’t adapt. - Replace the
Icons.imageplaceholder withImage.network, and put navigation inonTap.