import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'database.dart'; import 'song_list.dart'; class SearchScreen extends StatefulWidget { const SearchScreen({super.key}); @override State createState() => _SearchScreenState(); } class _SearchScreenState extends State { String _query = ''; @override Widget build(BuildContext context) { final db = context.read(); return Scaffold( appBar: AppBar( title: TextField( autofocus: false, decoration: const InputDecoration( hintText: 'Titel, Künstler, Album …', border: InputBorder.none, prefixIcon: Icon(Icons.search), ), onChanged: (v) => setState(() => _query = v.trim()), ), ), body: _query.isEmpty ? const Center( child: Text('Suchbegriff eingeben', style: TextStyle(color: Colors.white54)), ) : StreamBuilder>( stream: db.searchSongs(_query), 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 Center( child: Text('Nichts gefunden', style: TextStyle(color: Colors.white54)), ); } return SongList(songs); }, ), ); } }