import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'library/database.dart'; import 'library/library_service.dart'; import 'library/song_list.dart'; /// Startseite: zuletzt hinzugefügte Songs, sonst ein Willkommens-Hinweis. class HomeScreen extends StatelessWidget { const HomeScreen({super.key}); @override Widget build(BuildContext context) { final db = context.read(); return Scaffold( appBar: AppBar( title: const Text('Melo', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 26)), ), body: StreamBuilder>( stream: db.watchRecent(), builder: (context, snapshot) { if (snapshot.hasError) { return Center( child: Text('Fehler: ${snapshot.error}', style: const TextStyle(color: Colors.white54)), ); } final songs = snapshot.data ?? const []; if (songs.isEmpty) return const _Welcome(); return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const Padding( padding: EdgeInsets.fromLTRB(16, 8, 16, 8), child: Text('Zuletzt hinzugefügt', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600)), ), Expanded(child: SongList(songs)), ], ); }, ), ); } } class _Welcome extends StatelessWidget { const _Welcome(); @override Widget build(BuildContext context) { final lib = context.read(); return Center( child: Column( mainAxisSize: MainAxisSize.min, children: [ const Icon(Icons.music_note, size: 72, color: Colors.white24), const SizedBox(height: 12), const Text('Willkommen bei Melo', style: TextStyle(fontSize: 18)), const SizedBox(height: 4), const Text('Füge deine Musik hinzu, um loszulegen', style: TextStyle(color: Colors.white54)), const SizedBox(height: 20), FilledButton.icon( icon: const Icon(Icons.create_new_folder_outlined), label: Text(addMusicLabel), onPressed: lib.pickFolderAndScan, ), ], ), ); } }