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