import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'database.dart'; import 'library_service.dart'; import 'permissions.dart'; import 'song_list.dart'; class LibraryScreen extends StatelessWidget { const LibraryScreen({super.key}); @override Widget build(BuildContext context) { final db = context.read(); final lib = context.watch(); return Scaffold( appBar: AppBar( title: const Text('Bibliothek'), actions: [ IconButton( tooltip: addMusicLabel, icon: const Icon(Icons.create_new_folder_outlined), onPressed: lib.scanning ? null : lib.pickFolderAndScan, ), IconButton( tooltip: 'Erneut scannen', icon: const Icon(Icons.refresh), onPressed: lib.scanning ? null : lib.rescan, ), ], ), body: Column( children: [ if (lib.permissionDenied) MaterialBanner( backgroundColor: Colors.red.shade900, content: const Text('Zugriff auf Musik verweigert. ' 'Bitte in den Einstellungen erlauben.'), actions: [ TextButton( onPressed: openMusicPermissionSettings, child: const Text('Einstellungen'), ), ], ), if (lib.scanning) Padding( padding: const EdgeInsets.all(12), child: Column( children: [ const LinearProgressIndicator(), const SizedBox(height: 6), Text( 'Scanne … ${lib.scanDone}' '${lib.scanTotal > 0 ? ' / ${lib.scanTotal}' : ''}', style: const TextStyle(color: Colors.white54, fontSize: 12), ), ], ), ), Expanded( child: StreamBuilder>( stream: db.watchSongs(), builder: (context, snapshot) { final songs = snapshot.data ?? const []; if (songs.isEmpty && !lib.scanning) { return const _Empty(); } return SongList(songs); }, ), ), ], ), ); } } class _Empty extends StatelessWidget { const _Empty(); @override Widget build(BuildContext context) { final lib = context.read(); return Center( child: Column( mainAxisSize: MainAxisSize.min, children: [ const Icon(Icons.library_music, size: 64, color: Colors.white24), const SizedBox(height: 12), const Text('Noch keine Musik', style: TextStyle(color: Colors.white54)), const SizedBox(height: 16), FilledButton.icon( icon: const Icon(Icons.create_new_folder_outlined), label: Text(addMusicLabel), onPressed: lib.pickFolderAndScan, ), ], ), ); } }