53 lines
1.5 KiB
Dart
53 lines
1.5 KiB
Dart
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<SearchScreen> createState() => _SearchScreenState();
|
|
}
|
|
|
|
class _SearchScreenState extends State<SearchScreen> {
|
|
String _query = '';
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final db = context.read<MeloDb>();
|
|
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<List<Song>>(
|
|
stream: db.searchSongs(_query),
|
|
builder: (context, snapshot) {
|
|
final songs = snapshot.data ?? const [];
|
|
if (songs.isEmpty) {
|
|
return const Center(
|
|
child: Text('Nichts gefunden',
|
|
style: TextStyle(color: Colors.white54)),
|
|
);
|
|
}
|
|
return SongList(songs);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|