Travel Blog
Loading preview
Starting the Flutter app
A showcase of Flutter's travel blog functionality
import 'package:flutter/material.dart';
const _posts = [
{'title': '10 Hidden Gems in Tokyo', 'author': 'Sarah', 'date': 'Feb 28', 'likes': 234},
{'title': 'Best Beaches in Bali', 'author': 'Mike', 'date': 'Feb 25', 'likes': 189},
{'title': 'Santorini Sunset Guide', 'author': 'Emma', 'date': 'Feb 20', 'likes': 412},
];
class TravelBlog extends StatelessWidget {
const TravelBlog({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Travel Blog'),
actions: [
IconButton(tooltip: 'Search', icon: const Icon(Icons.search), onPressed: () => _showDemo(context, 'Search (demo)')),
],
),
body: ListView.builder(
padding: const EdgeInsets.all(16),
itemCount: _posts.length,
itemBuilder: (context, i) {
final p = _posts[i];
return Card(
margin: const EdgeInsets.only(bottom: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 180,
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: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
p['title'] as String,
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 8),
Row(
children: [
CircleAvatar(radius: 10, backgroundColor: Colors.grey[400]),
const SizedBox(width: 8),
Text('${p['author']} • ${p['date']}',
style: Theme.of(context).textTheme.bodySmall),
const Spacer(),
Icon(Icons.favorite_border, size: 18, color: Colors.grey[600]),
const SizedBox(width: 4),
Text('${p['likes']}', style: Theme.of(context).textTheme.bodySmall),
],
),
],
),
),
],
),
);
},
),
);
}
}
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
Cards with a 180px header, tinted from Colors.primaries with a modulo, plus a title and meta row, built with ListView.builder over _posts. The author avatar is a blank grey CircleAvatar. The heart is a plain Icon next to the like count, not a button, and the Card has no tap handling, so posts can’t be opened. Search only shows a demo SnackBar.
Adapting it
- Fetch
_postsfrom your CMS, and add image and slug fields. - Wrap each
CardinInkWellto open the article. - Change
Icons.favorite_borderto anIconButton, tracking likes per post.