## Critical Blockers Fixed - Remove playbackState.addError() which broke audio_service permanently - Move error handling from audio_handler to song_list where UI context exists - Display error in SnackBar instead of destroying playback stream - Add escapeChar parameter to LIKE queries for correct wildcard handling - Fixes broken search for titles with _ or % characters - Add dismissScanError() method to allow closing error banner - Previously banner couldn't be dismissed (missing notifyListeners()) ## Improvements - Remove dead livePaths list, use companions.isNotEmpty instead - Add initial progress update to show total files when scan starts - Add tooltip to now_playing_screen Zurück button - Add proper error handling in song_list with async/await ## Testing - Add regression test for CRITICAL-1: empty scan doesn't delete songs - Add regression test for CRITICAL-2: tombstoned files restore on re-scan - All 11 tests pass Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
121 lines
3.7 KiB
Dart
121 lines
3.7 KiB
Dart
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<MeloDb>();
|
|
final lib = context.watch<LibraryService>();
|
|
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.scanError != null)
|
|
MaterialBanner(
|
|
backgroundColor: Colors.red.shade900,
|
|
content: Text(lib.scanError!),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: lib.dismissScanError,
|
|
child: const Text('Verwerfen'),
|
|
),
|
|
],
|
|
),
|
|
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<List<Song>>(
|
|
stream: db.watchSongs(),
|
|
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 && !lib.scanning) {
|
|
return const _Empty();
|
|
}
|
|
return SongList(songs);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _Empty extends StatelessWidget {
|
|
const _Empty();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final lib = context.read<LibraryService>();
|
|
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,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|