parent
2668279899
commit
ffc5c95a55
Binary file not shown.
Binary file not shown.
@ -1 +1 @@
|
||||
d1b13d2690838e4bbcb8a4bdf95ce8b4
|
||||
7d34a1186938d51f8f2b6577f7a6094e
|
||||
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,275 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../common/download_manager.dart';
|
||||
import '../common_widget/Song_widegt.dart';
|
||||
import 'main_tab_view/main_tab_view.dart';
|
||||
import 'music_view.dart';
|
||||
|
||||
class SearchView extends StatefulWidget {
|
||||
const SearchView({super.key});
|
||||
|
||||
@override
|
||||
State<SearchView> createState() => _SearchViewState();
|
||||
}
|
||||
|
||||
class _SearchViewState extends State<SearchView> {
|
||||
final List<Song> songs = [];
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
final downloadManager = Get.put(DownloadManager());
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadMockData();
|
||||
}
|
||||
|
||||
void _loadMockData() {
|
||||
// 模拟数据
|
||||
final mockSongs = [
|
||||
Song(
|
||||
id: 1,
|
||||
title: "夜曲",
|
||||
artist: "周杰伦",
|
||||
artistPic: "https://example.com/jay.jpg",
|
||||
pic: "https://example.com/ye.jpg",
|
||||
musicurl: "https://example.com/music1.mp3",
|
||||
likes: false,
|
||||
collection: false,
|
||||
),
|
||||
Song(
|
||||
id: 2,
|
||||
title: "泡沫",
|
||||
artist: "邓紫棋",
|
||||
artistPic: "https://example.com/gem.jpg",
|
||||
pic: "https://example.com/foam.jpg",
|
||||
musicurl: "https://example.com/music2.mp3",
|
||||
likes: false,
|
||||
collection: false,
|
||||
),
|
||||
// 可以继续添加更多模拟数据
|
||||
];
|
||||
|
||||
setState(() {
|
||||
songs.clear();
|
||||
songs.addAll(mockSongs);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: const BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: AssetImage("assets/img/app_bg.png"),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.transparent,
|
||||
body: Column(
|
||||
children: [
|
||||
const SizedBox(height: 60),
|
||||
_buildSearchBar(),
|
||||
const SizedBox(height: 20),
|
||||
_buildPlayAllButton(),
|
||||
Expanded(
|
||||
child: _buildSongsList(),
|
||||
),
|
||||
MiniPlayer(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSearchBar() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Container(
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(25),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.1),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 5),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: TextField(
|
||||
controller: _searchController,
|
||||
decoration: InputDecoration(
|
||||
border: InputBorder.none,
|
||||
hintText: '搜索音乐、歌手',
|
||||
hintStyle: TextStyle(color: Colors.grey.shade400),
|
||||
prefixIcon: Icon(Icons.search, color: Colors.grey.shade400),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 20, vertical: 15),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPlayAllButton() {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 5,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: ListTile(
|
||||
onTap: () {
|
||||
if (songs.isNotEmpty) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => MusicView(
|
||||
songList: songs,
|
||||
initialSongIndex: 0,
|
||||
onSongStatusChanged: _updateSongStatus,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
leading: const Icon(Icons.play_circle_fill, color: Colors.blueGrey, size: 30),
|
||||
title: const Text(
|
||||
'播放全部',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
trailing: Text(
|
||||
'${songs.length}首',
|
||||
style: TextStyle(
|
||||
color: Colors.grey.shade600,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSongsList() {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(top: 10),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(30)),
|
||||
),
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.only(top: 10),
|
||||
itemCount: songs.length,
|
||||
itemBuilder: (context, index) => _buildSongItem(index),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSongItem(int index) {
|
||||
final song = songs[index];
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 5),
|
||||
child: InkWell(
|
||||
onTap: () => _onSongTap(index),
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 60,
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.1),
|
||||
blurRadius: 5,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Image.network(
|
||||
song.pic,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (context, error, stackTrace) =>
|
||||
const Icon(Icons.music_note, size: 30),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 15),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
song.title,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
song.artist,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.grey.shade600,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
Icons.more_vert,
|
||||
color: Colors.grey.shade400,
|
||||
),
|
||||
onPressed: () {
|
||||
// 实现更多操作的弹出菜单
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onSongTap(int index) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => MusicView(
|
||||
songList: songs,
|
||||
initialSongIndex: index,
|
||||
onSongStatusChanged: _updateSongStatus,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _updateSongStatus(int index, bool isCollected, bool isLiked) {
|
||||
setState(() {
|
||||
songs[index].collection = isCollected;
|
||||
songs[index].likes = isLiked;
|
||||
downloadManager.updateSongInfo(songs[index].id, isCollected, isLiked);
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue