Can filter playlist
This commit is contained in:
parent
702ce78a70
commit
a29e9dcfff
@ -45,6 +45,9 @@ class _MusicPlayerState extends State<MusicPlayer> {
|
||||
|
||||
var _showPlaylist = true;
|
||||
|
||||
final _filterController = fluent.TextEditingController();
|
||||
MusicsList? _filteredList;
|
||||
|
||||
MusicEntry get currMusic {
|
||||
if (currMusicPos < 0) currMusicPos = 0;
|
||||
|
||||
@ -113,6 +116,20 @@ class _MusicPlayerState extends State<MusicPlayer> {
|
||||
|
||||
void _updatePosition(Duration d) => _videoPlayerController?.seekTo(d);
|
||||
|
||||
void _refreshFilteredList() {
|
||||
final value = _filterController.value.text.toLowerCase();
|
||||
if (value.isEmpty) {
|
||||
setState(() => _filteredList = null);
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_filteredList = widget.musicsList
|
||||
.where((m) => m.fullName.toLowerCase().contains(value))
|
||||
.toList();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
@ -171,6 +188,7 @@ class _MusicPlayerState extends State<MusicPlayer> {
|
||||
_showPlaylist
|
||||
? SizedBox(
|
||||
width: playlistWidth,
|
||||
height: constraints.maxHeight,
|
||||
child: _buildPlaylistPane(),
|
||||
)
|
||||
: Container(),
|
||||
@ -261,17 +279,28 @@ class _MusicPlayerState extends State<MusicPlayer> {
|
||||
);
|
||||
|
||||
Widget _buildPlaylistPane() {
|
||||
return ListView.builder(
|
||||
itemBuilder: (c, i) {
|
||||
final music = widget.musicsList[i];
|
||||
return ListTile(
|
||||
title: Text(music.title),
|
||||
subtitle: Text(music.artist),
|
||||
selected: currMusic == music,
|
||||
onTap: () => _playMusic(music),
|
||||
);
|
||||
},
|
||||
itemCount: widget.musicsList.length,
|
||||
return Column(
|
||||
children: [
|
||||
fluent.TextBox(
|
||||
controller: _filterController,
|
||||
placeholder: "Filter list...",
|
||||
onChanged: (s) => _refreshFilteredList(),
|
||||
),
|
||||
Flexible(
|
||||
child: ListView.builder(
|
||||
itemBuilder: (c, i) {
|
||||
final music = (_filteredList ?? widget.musicsList)[i];
|
||||
return ListTile(
|
||||
title: Text(music.title),
|
||||
subtitle: Text(music.artist),
|
||||
selected: currMusic == music,
|
||||
onTap: () => _playMusic(music),
|
||||
);
|
||||
},
|
||||
itemCount: (_filteredList ?? widget.musicsList).length,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user