5ef782905e
Sections mirror the web home: Recently added · Rediscover (albums + artists) · Most played · Last played artists. Tap routes pushed for albums/artists; track-tap is wired in the player task. Pull-to-refresh re-fetches /api/home.
74 lines
2.5 KiB
Dart
74 lines
2.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
import '../models/album.dart';
|
|
import '../models/artist.dart';
|
|
import '../models/track.dart';
|
|
import '../theme/theme_extension.dart';
|
|
import 'library_providers.dart';
|
|
import 'widgets/album_card.dart';
|
|
import 'widgets/artist_card.dart';
|
|
import 'widgets/horizontal_scroll_row.dart';
|
|
import 'widgets/track_row.dart';
|
|
|
|
class HomeScreen extends ConsumerWidget {
|
|
const HomeScreen({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final fs = Theme.of(context).extension<FabledSwordTheme>()!;
|
|
return Scaffold(
|
|
backgroundColor: fs.obsidian,
|
|
body: SafeArea(
|
|
child: ref.watch(homeProvider).when(
|
|
error: (e, _) => Center(child: Text('$e', style: TextStyle(color: fs.error))),
|
|
loading: () => const Center(child: CircularProgressIndicator()),
|
|
data: (h) => RefreshIndicator(
|
|
onRefresh: () async => ref.refresh(homeProvider.future),
|
|
child: ListView(children: [
|
|
_albumsRow(context, 'Recently added', h.recentlyAddedAlbums),
|
|
_albumsRow(context, 'Rediscover', h.rediscoverAlbums),
|
|
_artistsRow(context, 'Rediscover artists', h.rediscoverArtists),
|
|
_tracksRow(context, ref, 'Most played', h.mostPlayedTracks),
|
|
_artistsRow(context, 'Last played artists', h.lastPlayedArtists),
|
|
const SizedBox(height: 96),
|
|
]),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _albumsRow(BuildContext ctx, String title, List<AlbumRef> albums) =>
|
|
HorizontalScrollRow(
|
|
title: title,
|
|
children: [
|
|
for (final a in albums)
|
|
AlbumCard(album: a, onTap: () => ctx.push('/albums/${a.id}')),
|
|
],
|
|
);
|
|
|
|
Widget _artistsRow(BuildContext ctx, String title, List<ArtistRef> artists) =>
|
|
HorizontalScrollRow(
|
|
title: title,
|
|
children: [
|
|
for (final a in artists)
|
|
ArtistCard(artist: a, onTap: () => ctx.push('/artists/${a.id}')),
|
|
],
|
|
);
|
|
|
|
Widget _tracksRow(BuildContext ctx, WidgetRef ref, String title, List<TrackRef> tracks) =>
|
|
HorizontalScrollRow(
|
|
title: title,
|
|
height: 64,
|
|
children: [
|
|
for (final t in tracks)
|
|
SizedBox(
|
|
width: 280,
|
|
child: TrackRow(track: t, onTap: () { /* play wired in Task 18 */ }),
|
|
),
|
|
],
|
|
);
|
|
}
|