Album Grid
Loading preview
Starting the Flutter app
A showcase of Flutter's album grid functionality
import 'package:flutter/material.dart';
const _albums = [
{'name': 'Album One', 'artist': 'Artist A'},
{'name': 'Album Two', 'artist': 'Artist B'},
{'name': 'Album Three', 'artist': 'Artist A'},
{'name': 'Album Four', 'artist': 'Artist C'},
];
class AlbumGrid extends StatelessWidget {
const AlbumGrid({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Albums')),
body: GridView.builder(
padding: const EdgeInsets.all(16),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: MediaQuery.of(context).size.width > 600 ? 4 : 2,
childAspectRatio: 0.85,
crossAxisSpacing: 16,
mainAxisSpacing: 16,
),
itemCount: _albums.length,
itemBuilder: (context, i) {
final a = _albums[i];
return Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Container(
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(8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
a['name'] as String,
style: Theme.of(context).textTheme.titleSmall,
),
Text(
a['artist'] as String,
style: Theme.of(context).textTheme.bodySmall,
),
],
),
),
],
),
);
},
),
);
}
}
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
GridView.builder lays out _albums in two columns, or four when MediaQuery reports a width above 600. Each Card has a colored block standing in for cover art, tinted from Colors.primaries with a modulo, and a name and artist below. Cards aren’t tappable, and tints repeat on lists longer than the palette.
Adapting it
- Replace the placeholder
ContainerwithImage.network, and clip it to the card’s top corners. - Add
InkWellaround eachCardto open the album. - Swap
SliverGridDelegateWithFixedCrossAxisCountfor the max-extent delegate if column count should scale without a single breakpoint.