Destination Cards
Loading preview
Starting the Flutter app
A showcase of Flutter's destination cards functionality
import 'package:flutter/material.dart';
const _destinations = [
{'name': 'Paris', 'country': 'France', 'price': '\$899', 'rating': 4.8},
{'name': 'Tokyo', 'country': 'Japan', 'price': '\$1,299', 'rating': 4.9},
{'name': 'Santorini', 'country': 'Greece', 'price': '\$749', 'rating': 4.7},
{'name': 'Bali', 'country': 'Indonesia', 'price': '\$599', 'rating': 4.6},
];
class DestinationCards extends StatelessWidget {
const DestinationCards({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Destinations')),
body: ListView(
padding: const EdgeInsets.all(16),
children: _destinations.asMap().entries.map((e) {
final i = e.key;
final d = e.value;
return Card(
margin: const EdgeInsets.only(bottom: 12),
child: InkWell(
onTap: () => _showDemo(context, 'Open ${d['name']} (demo)'),
borderRadius: BorderRadius.circular(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 160,
decoration: BoxDecoration(
color: Colors.primaries[i % Colors.primaries.length]
.withValues(alpha: 0.3),
borderRadius: const BorderRadius.vertical(
top: Radius.circular(12),
),
),
),
Padding(
padding: const EdgeInsets.all(16),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
d['name'] as String,
style: Theme.of(context).textTheme.titleLarge,
),
Text(
d['country'] as String,
style: Theme.of(context).textTheme.bodyMedium,
),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
d['price'] as String,
style: Theme.of(context).textTheme.titleMedium,
),
Row(
children: [
Icon(Icons.star, size: 16, color: Colors.amber[700]),
const SizedBox(width: 4),
Text('${d['rating']}'),
],
),
],
),
],
),
),
],
),
),
);
}).toList(),
),
);
}
}
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
_destinations.asMap() gives each Card an index for its tint, safely wrapped by i % Colors.primaries.length. A 160px colored block stands in for a photo, with name and country opposite price and rating. price is a preformatted string, so it can’t be sorted numerically. The InkWell’s onTap shows a demo SnackBar.
Adapting it
- Replace the colored
ContainerwithImage.network, and setclipBehavioronCard. - Store
priceas a number, formatting it withintl. - Push a detail page from
onTap, usingHeroon the image.