fix: 修复Mini播放器初始化数组大小为0的bug

chen
Spark 8 months ago
parent ffc5c95a55
commit 10d326f3ff

File diff suppressed because one or more lines are too long

@ -287,7 +287,7 @@ class _HomeViewState extends State<HomeView>
),
const SizedBox(width: 10),
const Text(
"大家都在搜《背对背拥抱》",
"搜索你想找的音乐",
style: TextStyle(
color: Color(0xffA5A5A5),
fontSize: 13,

@ -158,9 +158,9 @@ class MiniPlayer extends StatelessWidget {
Widget build(BuildContext context) {
return Obx(() {
final bool hasPlaylist = audioController.songList.isNotEmpty;
return GestureDetector(
onHorizontalDragEnd: hasPlaylist ? (DragEndDetails details) {
onHorizontalDragEnd: hasPlaylist
? (DragEndDetails details) {
if (audioController.songList.isEmpty) return;
final velocity = details.velocity.pixelsPerSecond.dx;
const threshold = 300.0;
@ -172,7 +172,8 @@ class MiniPlayer extends StatelessWidget {
audioController.playNext();
HapticFeedback.mediumImpact();
}
} : null,
}
: null,
child: Container(
height: 64, // 使
decoration: BoxDecoration(
@ -213,6 +214,9 @@ class MiniPlayer extends StatelessWidget {
BuildContext fromHeroContext,
BuildContext toHeroContext,
) {
if (!hasPlaylist) {
return const Icon(Icons.music_note, size: 30);
}
return ClipRRect(
borderRadius: BorderRadius.circular(8),
clipBehavior: Clip.hardEdge,
@ -220,7 +224,10 @@ class MiniPlayer extends StatelessWidget {
width: 48,
height: 48,
child: Image.network(
audioController.songList[audioController.currentSongIndex.value].pic,
audioController
.songList[
audioController.currentSongIndex.value]
.pic,
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) =>
const Icon(Icons.music_note, size: 30),
@ -234,7 +241,8 @@ class MiniPlayer extends StatelessWidget {
child: Obx(() {
final currentSong = audioController.songList.isEmpty
? null
: audioController.songList[audioController.currentSongIndex.value];
: audioController.songList[
audioController.currentSongIndex.value];
return AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
child: currentSong != null
@ -246,25 +254,6 @@ class MiniPlayer extends StatelessWidget {
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) =>
const Icon(Icons.music_note, size: 30),
// loadingBuilder: (context, child, loadingProgress) {
// if (loadingProgress == null) return child;
// return Container(
// color: Colors.grey[100],
// width: 48,
// height: 48,
// child: Center(
// child: CircularProgressIndicator(
// strokeWidth: 2,
// valueColor: const AlwaysStoppedAnimation<Color>(
// Color(0xff429482)),
// value: loadingProgress.expectedTotalBytes != null
// ? loadingProgress.cumulativeBytesLoaded /
// loadingProgress.expectedTotalBytes!
// : null,
// ),
// ),
// );
// },
)
: const Icon(Icons.music_note, size: 30),
);

@ -1,7 +1,10 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../api/api_music_list.dart';
import '../common/download_manager.dart';
import '../common_widget/Song_widegt.dart';
import '../common_widget/app_data.dart';
import '../models/MusicsListBean.dart';
import 'main_tab_view/main_tab_view.dart';
import 'music_view.dart';
@ -20,40 +23,30 @@ class _SearchViewState extends State<SearchView> {
@override
void initState() {
super.initState();
_loadMockData();
_loadRecommendData();
}
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,
),
//
];
void _loadRecommendData() async {
MusicsListBean bean = await GetMusic()
.getMusicList(Authorization: AppData().currentToken, num: 10);
if (bean.code == 200) {
setState(() {
songs.clear();
songs.addAll(mockSongs);
for (var data in bean.data!) {
songs.add(Song(
artistPic: data.coverPath!,
title: data.name!,
artist: data.singerName!,
musicurl: data.musicPath!,
pic: data.coverPath!,
id: data.id!,
likes: data.likeOrNot!,
collection: data.collectOrNot!,
));
}
});
}
}
@override
Widget build(BuildContext context) {
@ -76,6 +69,7 @@ class _SearchViewState extends State<SearchView> {
child: _buildSongsList(),
),
MiniPlayer(),
const SizedBox(height: 10),
],
),
),
@ -102,10 +96,11 @@ class _SearchViewState extends State<SearchView> {
controller: _searchController,
decoration: InputDecoration(
border: InputBorder.none,
hintText: '搜索音乐、歌手',
hintText: '搜索你想找的音乐',
hintStyle: TextStyle(color: Colors.grey.shade400),
prefixIcon: Icon(Icons.search, color: Colors.grey.shade400),
contentPadding: const EdgeInsets.symmetric(horizontal: 20, vertical: 15),
contentPadding:
const EdgeInsets.symmetric(horizontal: 20, vertical: 15),
),
),
),
@ -141,7 +136,8 @@ class _SearchViewState extends State<SearchView> {
);
}
},
leading: const Icon(Icons.play_circle_fill, color: Colors.blueGrey, size: 30),
leading: const Icon(Icons.play_circle_fill,
color: Colors.blueGrey, size: 30),
title: const Text(
'播放全部',
style: TextStyle(

Loading…
Cancel
Save