fix: 修复音乐上传BUG

chen
Spark 3 months ago
parent 79086ea659
commit e550ee2de3

File diff suppressed because one or more lines are too long

@ -1 +1 @@
{"assets/audio/All.mp3":["assets/audio/All.mp3"],"assets/audio/FLOWER.mp3":["assets/audio/FLOWER.mp3"],"assets/audio/MAMAMOO.mp3":["assets/audio/MAMAMOO.mp3"],"assets/audio/Travel.mp3":["assets/audio/Travel.mp3"],"assets/img/More.png":["assets/img/More.png"],"assets/img/add.png":["assets/img/add.png"],"assets/img/app_bg.png":["assets/img/app_bg.png"],"assets/img/app_logo.png":["assets/img/app_logo.png"],"assets/img/artist_pic.png":["assets/img/artist_pic.png"],"assets/img/back.png":["assets/img/back.png"],"assets/img/banner.png":["assets/img/banner.png"],"assets/img/banner1.png":["assets/img/banner1.png"],"assets/img/banner2.png":["assets/img/banner2.png"],"assets/img/bingo.png":["assets/img/bingo.png"],"assets/img/button_play.png":["assets/img/button_play.png"],"assets/img/commend_down.png":["assets/img/commend_down.png"],"assets/img/commend_up.png":["assets/img/commend_up.png"],"assets/img/correct.png":["assets/img/correct.png"],"assets/img/delete.png":["assets/img/delete.png"],"assets/img/home_search.png":["assets/img/home_search.png"],"assets/img/home_tab.png":["assets/img/home_tab.png"],"assets/img/home_tab_un.png":["assets/img/home_tab_un.png"],"assets/img/list_add.png":["assets/img/list_add.png"],"assets/img/list_collection.png":["assets/img/list_collection.png"],"assets/img/list_comment.png":["assets/img/list_comment.png"],"assets/img/list_download.png":["assets/img/list_download.png"],"assets/img/list_good.png":["assets/img/list_good.png"],"assets/img/list_good_act.png":["assets/img/list_good_act.png"],"assets/img/list_op.png":["assets/img/list_op.png"],"assets/img/list_pic.png":["assets/img/list_pic.png"],"assets/img/list_pic1.png":["assets/img/list_pic1.png"],"assets/img/list_pic2.png":["assets/img/list_pic2.png"],"assets/img/list_pic3.png":["assets/img/list_pic3.png"],"assets/img/list_pic4.png":["assets/img/list_pic4.png"],"assets/img/list_remove.png":["assets/img/list_remove.png"],"assets/img/list_tab.png":["assets/img/list_tab.png"],"assets/img/list_tab_un.png":["assets/img/list_tab_un.png"],"assets/img/login_lock.png":["assets/img/login_lock.png"],"assets/img/login_user.png":["assets/img/login_user.png"],"assets/img/music_Ellipse.png":["assets/img/music_Ellipse.png"],"assets/img/music_add.png":["assets/img/music_add.png"],"assets/img/music_artist.png":["assets/img/music_artist.png"],"assets/img/music_back.png":["assets/img/music_back.png"],"assets/img/music_commend_un.png":["assets/img/music_commend_un.png"],"assets/img/music_download.png":["assets/img/music_download.png"],"assets/img/music_download_completed.png":["assets/img/music_download_completed.png"],"assets/img/music_for.png":["assets/img/music_for.png"],"assets/img/music_good.png":["assets/img/music_good.png"],"assets/img/music_good_un.png":["assets/img/music_good_un.png"],"assets/img/music_loop.png":["assets/img/music_loop.png"],"assets/img/music_more.png":["assets/img/music_more.png"],"assets/img/music_next.png":["assets/img/music_next.png"],"assets/img/music_pause.png":["assets/img/music_pause.png"],"assets/img/music_play.png":["assets/img/music_play.png"],"assets/img/music_random.png":["assets/img/music_random.png"],"assets/img/music_star.png":["assets/img/music_star.png"],"assets/img/music_star_un.png":["assets/img/music_star_un.png"],"assets/img/music_tab.png":["assets/img/music_tab.png"],"assets/img/music_tab_un.png":["assets/img/music_tab_un.png"],"assets/img/release_delete.png":["assets/img/release_delete.png"],"assets/img/release_download1.png":["assets/img/release_download1.png"],"assets/img/release_info.png":["assets/img/release_info.png"],"assets/img/release_pic.png":["assets/img/release_pic.png"],"assets/img/release_pic1.png":["assets/img/release_pic1.png"],"assets/img/release_upload.png":["assets/img/release_upload.png"],"assets/img/setup_confirm.png":["assets/img/setup_confirm.png"],"assets/img/setup_email.png":["assets/img/setup_email.png"],"assets/img/song_cover1.png":["assets/img/song_cover1.png"],"assets/img/song_cover2.png":["assets/img/song_cover2.png"],"assets/img/song_cover3.png":["assets/img/song_cover3.png"],"assets/img/songs_run.png":["assets/img/songs_run.png"],"assets/img/user_add.png":["assets/img/user_add.png"],"assets/img/user_export.png":["assets/img/user_export.png"],"assets/img/user_head.png":["assets/img/user_head.png"],"assets/img/user_infor.png":["assets/img/user_infor.png"],"assets/img/user_more.png":["assets/img/user_more.png"],"assets/img/user_next.png":["assets/img/user_next.png"],"assets/img/user_out.png":["assets/img/user_out.png"],"assets/img/user_tab.png":["assets/img/user_tab.png"],"assets/img/user_tab_un.png":["assets/img/user_tab_un.png"],"assets/img/warning.png":["assets/img/warning.png"],"packages/cupertino_icons/assets/CupertinoIcons.ttf":["packages/cupertino_icons/assets/CupertinoIcons.ttf"]}
{"assets/audio/All.mp3":["assets/audio/All.mp3"],"assets/audio/FLOWER.mp3":["assets/audio/FLOWER.mp3"],"assets/audio/MAMAMOO.mp3":["assets/audio/MAMAMOO.mp3"],"assets/audio/Travel.mp3":["assets/audio/Travel.mp3"],"assets/img/More.png":["assets/img/More.png"],"assets/img/add.png":["assets/img/add.png"],"assets/img/app_bg.png":["assets/img/app_bg.png"],"assets/img/app_logo.png":["assets/img/app_logo.png"],"assets/img/artist_pic.png":["assets/img/artist_pic.png"],"assets/img/back.png":["assets/img/back.png"],"assets/img/banner.png":["assets/img/banner.png"],"assets/img/banner1.png":["assets/img/banner1.png"],"assets/img/banner2.png":["assets/img/banner2.png"],"assets/img/bingo.png":["assets/img/bingo.png"],"assets/img/button_play.png":["assets/img/button_play.png"],"assets/img/commend_down.png":["assets/img/commend_down.png"],"assets/img/commend_up.png":["assets/img/commend_up.png"],"assets/img/correct.png":["assets/img/correct.png"],"assets/img/delete.png":["assets/img/delete.png"],"assets/img/home_search.png":["assets/img/home_search.png"],"assets/img/home_tab.png":["assets/img/home_tab.png"],"assets/img/home_tab_un.png":["assets/img/home_tab_un.png"],"assets/img/list_add.png":["assets/img/list_add.png"],"assets/img/list_collection.png":["assets/img/list_collection.png"],"assets/img/list_comment.png":["assets/img/list_comment.png"],"assets/img/list_download.png":["assets/img/list_download.png"],"assets/img/list_good.png":["assets/img/list_good.png"],"assets/img/list_good_act.png":["assets/img/list_good_act.png"],"assets/img/list_op.png":["assets/img/list_op.png"],"assets/img/list_pic.png":["assets/img/list_pic.png"],"assets/img/list_pic1.png":["assets/img/list_pic1.png"],"assets/img/list_pic2.png":["assets/img/list_pic2.png"],"assets/img/list_pic3.png":["assets/img/list_pic3.png"],"assets/img/list_pic4.png":["assets/img/list_pic4.png"],"assets/img/list_remove.png":["assets/img/list_remove.png"],"assets/img/list_tab.png":["assets/img/list_tab.png"],"assets/img/list_tab_un.png":["assets/img/list_tab_un.png"],"assets/img/login_lock.png":["assets/img/login_lock.png"],"assets/img/login_user.png":["assets/img/login_user.png"],"assets/img/music_Ellipse.ba.png":["assets/img/music_Ellipse.ba.png"],"assets/img/music_Ellipse.png":["assets/img/music_Ellipse.png"],"assets/img/music_add.png":["assets/img/music_add.png"],"assets/img/music_artist.png":["assets/img/music_artist.png"],"assets/img/music_back.png":["assets/img/music_back.png"],"assets/img/music_commend_un.png":["assets/img/music_commend_un.png"],"assets/img/music_download.png":["assets/img/music_download.png"],"assets/img/music_download_completed.png":["assets/img/music_download_completed.png"],"assets/img/music_for.png":["assets/img/music_for.png"],"assets/img/music_good.png":["assets/img/music_good.png"],"assets/img/music_good_un.png":["assets/img/music_good_un.png"],"assets/img/music_loop.png":["assets/img/music_loop.png"],"assets/img/music_more.png":["assets/img/music_more.png"],"assets/img/music_next.png":["assets/img/music_next.png"],"assets/img/music_pause.png":["assets/img/music_pause.png"],"assets/img/music_play.png":["assets/img/music_play.png"],"assets/img/music_random.png":["assets/img/music_random.png"],"assets/img/music_star.png":["assets/img/music_star.png"],"assets/img/music_star_un.png":["assets/img/music_star_un.png"],"assets/img/music_tab.png":["assets/img/music_tab.png"],"assets/img/music_tab_un.png":["assets/img/music_tab_un.png"],"assets/img/release_delete.png":["assets/img/release_delete.png"],"assets/img/release_download1.png":["assets/img/release_download1.png"],"assets/img/release_info.png":["assets/img/release_info.png"],"assets/img/release_pic.png":["assets/img/release_pic.png"],"assets/img/release_pic1.png":["assets/img/release_pic1.png"],"assets/img/release_upload.png":["assets/img/release_upload.png"],"assets/img/setup_confirm.png":["assets/img/setup_confirm.png"],"assets/img/setup_email.png":["assets/img/setup_email.png"],"assets/img/song_cover1.png":["assets/img/song_cover1.png"],"assets/img/song_cover2.png":["assets/img/song_cover2.png"],"assets/img/song_cover3.png":["assets/img/song_cover3.png"],"assets/img/songs_run.png":["assets/img/songs_run.png"],"assets/img/user_add.png":["assets/img/user_add.png"],"assets/img/user_export.png":["assets/img/user_export.png"],"assets/img/user_head.png":["assets/img/user_head.png"],"assets/img/user_infor.png":["assets/img/user_infor.png"],"assets/img/user_more.png":["assets/img/user_more.png"],"assets/img/user_next.png":["assets/img/user_next.png"],"assets/img/user_out.png":["assets/img/user_out.png"],"assets/img/user_tab.png":["assets/img/user_tab.png"],"assets/img/user_tab_un.png":["assets/img/user_tab_un.png"],"assets/img/warning.png":["assets/img/warning.png"],"packages/cupertino_icons/assets/CupertinoIcons.ttf":["packages/cupertino_icons/assets/CupertinoIcons.ttf"]}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 299 KiB

File diff suppressed because one or more lines are too long

@ -1 +1 @@
{"assets/audio/All.mp3":["assets/audio/All.mp3"],"assets/audio/FLOWER.mp3":["assets/audio/FLOWER.mp3"],"assets/audio/MAMAMOO.mp3":["assets/audio/MAMAMOO.mp3"],"assets/audio/Travel.mp3":["assets/audio/Travel.mp3"],"assets/img/More.png":["assets/img/More.png"],"assets/img/add.png":["assets/img/add.png"],"assets/img/app_bg.png":["assets/img/app_bg.png"],"assets/img/app_logo.png":["assets/img/app_logo.png"],"assets/img/artist_pic.png":["assets/img/artist_pic.png"],"assets/img/back.png":["assets/img/back.png"],"assets/img/banner.png":["assets/img/banner.png"],"assets/img/banner1.png":["assets/img/banner1.png"],"assets/img/banner2.png":["assets/img/banner2.png"],"assets/img/bingo.png":["assets/img/bingo.png"],"assets/img/button_play.png":["assets/img/button_play.png"],"assets/img/commend_down.png":["assets/img/commend_down.png"],"assets/img/commend_up.png":["assets/img/commend_up.png"],"assets/img/correct.png":["assets/img/correct.png"],"assets/img/delete.png":["assets/img/delete.png"],"assets/img/home_search.png":["assets/img/home_search.png"],"assets/img/home_tab.png":["assets/img/home_tab.png"],"assets/img/home_tab_un.png":["assets/img/home_tab_un.png"],"assets/img/list_add.png":["assets/img/list_add.png"],"assets/img/list_collection.png":["assets/img/list_collection.png"],"assets/img/list_comment.png":["assets/img/list_comment.png"],"assets/img/list_download.png":["assets/img/list_download.png"],"assets/img/list_good.png":["assets/img/list_good.png"],"assets/img/list_good_act.png":["assets/img/list_good_act.png"],"assets/img/list_op.png":["assets/img/list_op.png"],"assets/img/list_pic.png":["assets/img/list_pic.png"],"assets/img/list_pic1.png":["assets/img/list_pic1.png"],"assets/img/list_pic2.png":["assets/img/list_pic2.png"],"assets/img/list_pic3.png":["assets/img/list_pic3.png"],"assets/img/list_pic4.png":["assets/img/list_pic4.png"],"assets/img/list_remove.png":["assets/img/list_remove.png"],"assets/img/list_tab.png":["assets/img/list_tab.png"],"assets/img/list_tab_un.png":["assets/img/list_tab_un.png"],"assets/img/login_lock.png":["assets/img/login_lock.png"],"assets/img/login_user.png":["assets/img/login_user.png"],"assets/img/music_Ellipse.png":["assets/img/music_Ellipse.png"],"assets/img/music_add.png":["assets/img/music_add.png"],"assets/img/music_artist.png":["assets/img/music_artist.png"],"assets/img/music_back.png":["assets/img/music_back.png"],"assets/img/music_commend_un.png":["assets/img/music_commend_un.png"],"assets/img/music_download.png":["assets/img/music_download.png"],"assets/img/music_download_completed.png":["assets/img/music_download_completed.png"],"assets/img/music_for.png":["assets/img/music_for.png"],"assets/img/music_good.png":["assets/img/music_good.png"],"assets/img/music_good_un.png":["assets/img/music_good_un.png"],"assets/img/music_loop.png":["assets/img/music_loop.png"],"assets/img/music_more.png":["assets/img/music_more.png"],"assets/img/music_next.png":["assets/img/music_next.png"],"assets/img/music_pause.png":["assets/img/music_pause.png"],"assets/img/music_play.png":["assets/img/music_play.png"],"assets/img/music_random.png":["assets/img/music_random.png"],"assets/img/music_star.png":["assets/img/music_star.png"],"assets/img/music_star_un.png":["assets/img/music_star_un.png"],"assets/img/music_tab.png":["assets/img/music_tab.png"],"assets/img/music_tab_un.png":["assets/img/music_tab_un.png"],"assets/img/release_delete.png":["assets/img/release_delete.png"],"assets/img/release_download1.png":["assets/img/release_download1.png"],"assets/img/release_info.png":["assets/img/release_info.png"],"assets/img/release_pic.png":["assets/img/release_pic.png"],"assets/img/release_pic1.png":["assets/img/release_pic1.png"],"assets/img/release_upload.png":["assets/img/release_upload.png"],"assets/img/setup_confirm.png":["assets/img/setup_confirm.png"],"assets/img/setup_email.png":["assets/img/setup_email.png"],"assets/img/song_cover1.png":["assets/img/song_cover1.png"],"assets/img/song_cover2.png":["assets/img/song_cover2.png"],"assets/img/song_cover3.png":["assets/img/song_cover3.png"],"assets/img/songs_run.png":["assets/img/songs_run.png"],"assets/img/user_add.png":["assets/img/user_add.png"],"assets/img/user_export.png":["assets/img/user_export.png"],"assets/img/user_head.png":["assets/img/user_head.png"],"assets/img/user_infor.png":["assets/img/user_infor.png"],"assets/img/user_more.png":["assets/img/user_more.png"],"assets/img/user_next.png":["assets/img/user_next.png"],"assets/img/user_out.png":["assets/img/user_out.png"],"assets/img/user_tab.png":["assets/img/user_tab.png"],"assets/img/user_tab_un.png":["assets/img/user_tab_un.png"],"assets/img/warning.png":["assets/img/warning.png"],"packages/cupertino_icons/assets/CupertinoIcons.ttf":["packages/cupertino_icons/assets/CupertinoIcons.ttf"]}
{"assets/audio/All.mp3":["assets/audio/All.mp3"],"assets/audio/FLOWER.mp3":["assets/audio/FLOWER.mp3"],"assets/audio/MAMAMOO.mp3":["assets/audio/MAMAMOO.mp3"],"assets/audio/Travel.mp3":["assets/audio/Travel.mp3"],"assets/img/More.png":["assets/img/More.png"],"assets/img/add.png":["assets/img/add.png"],"assets/img/app_bg.png":["assets/img/app_bg.png"],"assets/img/app_logo.png":["assets/img/app_logo.png"],"assets/img/artist_pic.png":["assets/img/artist_pic.png"],"assets/img/back.png":["assets/img/back.png"],"assets/img/banner.png":["assets/img/banner.png"],"assets/img/banner1.png":["assets/img/banner1.png"],"assets/img/banner2.png":["assets/img/banner2.png"],"assets/img/bingo.png":["assets/img/bingo.png"],"assets/img/button_play.png":["assets/img/button_play.png"],"assets/img/commend_down.png":["assets/img/commend_down.png"],"assets/img/commend_up.png":["assets/img/commend_up.png"],"assets/img/correct.png":["assets/img/correct.png"],"assets/img/delete.png":["assets/img/delete.png"],"assets/img/home_search.png":["assets/img/home_search.png"],"assets/img/home_tab.png":["assets/img/home_tab.png"],"assets/img/home_tab_un.png":["assets/img/home_tab_un.png"],"assets/img/list_add.png":["assets/img/list_add.png"],"assets/img/list_collection.png":["assets/img/list_collection.png"],"assets/img/list_comment.png":["assets/img/list_comment.png"],"assets/img/list_download.png":["assets/img/list_download.png"],"assets/img/list_good.png":["assets/img/list_good.png"],"assets/img/list_good_act.png":["assets/img/list_good_act.png"],"assets/img/list_op.png":["assets/img/list_op.png"],"assets/img/list_pic.png":["assets/img/list_pic.png"],"assets/img/list_pic1.png":["assets/img/list_pic1.png"],"assets/img/list_pic2.png":["assets/img/list_pic2.png"],"assets/img/list_pic3.png":["assets/img/list_pic3.png"],"assets/img/list_pic4.png":["assets/img/list_pic4.png"],"assets/img/list_remove.png":["assets/img/list_remove.png"],"assets/img/list_tab.png":["assets/img/list_tab.png"],"assets/img/list_tab_un.png":["assets/img/list_tab_un.png"],"assets/img/login_lock.png":["assets/img/login_lock.png"],"assets/img/login_user.png":["assets/img/login_user.png"],"assets/img/music_Ellipse.ba.png":["assets/img/music_Ellipse.ba.png"],"assets/img/music_Ellipse.png":["assets/img/music_Ellipse.png"],"assets/img/music_add.png":["assets/img/music_add.png"],"assets/img/music_artist.png":["assets/img/music_artist.png"],"assets/img/music_back.png":["assets/img/music_back.png"],"assets/img/music_commend_un.png":["assets/img/music_commend_un.png"],"assets/img/music_download.png":["assets/img/music_download.png"],"assets/img/music_download_completed.png":["assets/img/music_download_completed.png"],"assets/img/music_for.png":["assets/img/music_for.png"],"assets/img/music_good.png":["assets/img/music_good.png"],"assets/img/music_good_un.png":["assets/img/music_good_un.png"],"assets/img/music_loop.png":["assets/img/music_loop.png"],"assets/img/music_more.png":["assets/img/music_more.png"],"assets/img/music_next.png":["assets/img/music_next.png"],"assets/img/music_pause.png":["assets/img/music_pause.png"],"assets/img/music_play.png":["assets/img/music_play.png"],"assets/img/music_random.png":["assets/img/music_random.png"],"assets/img/music_star.png":["assets/img/music_star.png"],"assets/img/music_star_un.png":["assets/img/music_star_un.png"],"assets/img/music_tab.png":["assets/img/music_tab.png"],"assets/img/music_tab_un.png":["assets/img/music_tab_un.png"],"assets/img/release_delete.png":["assets/img/release_delete.png"],"assets/img/release_download1.png":["assets/img/release_download1.png"],"assets/img/release_info.png":["assets/img/release_info.png"],"assets/img/release_pic.png":["assets/img/release_pic.png"],"assets/img/release_pic1.png":["assets/img/release_pic1.png"],"assets/img/release_upload.png":["assets/img/release_upload.png"],"assets/img/setup_confirm.png":["assets/img/setup_confirm.png"],"assets/img/setup_email.png":["assets/img/setup_email.png"],"assets/img/song_cover1.png":["assets/img/song_cover1.png"],"assets/img/song_cover2.png":["assets/img/song_cover2.png"],"assets/img/song_cover3.png":["assets/img/song_cover3.png"],"assets/img/songs_run.png":["assets/img/songs_run.png"],"assets/img/user_add.png":["assets/img/user_add.png"],"assets/img/user_export.png":["assets/img/user_export.png"],"assets/img/user_head.png":["assets/img/user_head.png"],"assets/img/user_infor.png":["assets/img/user_infor.png"],"assets/img/user_more.png":["assets/img/user_more.png"],"assets/img/user_next.png":["assets/img/user_next.png"],"assets/img/user_out.png":["assets/img/user_out.png"],"assets/img/user_tab.png":["assets/img/user_tab.png"],"assets/img/user_tab_un.png":["assets/img/user_tab_un.png"],"assets/img/warning.png":["assets/img/warning.png"],"packages/cupertino_icons/assets/CupertinoIcons.ttf":["packages/cupertino_icons/assets/CupertinoIcons.ttf"]}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 299 KiB

File diff suppressed because one or more lines are too long

@ -1,4 +1,4 @@
#Sat Nov 16 21:39:53 CST 2024
#Sat Nov 23 15:12:04 CST 2024
path.4=1/classes.dex
path.3=15/classes.dex
path.2=13/classes.dex

@ -1,9 +1,10 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:file_picker/file_picker.dart';
import 'package:dio/dio.dart'; // dio
import 'package:path/path.dart' as path; // path
import 'package:music_player_miao/common_widget/app_data.dart';
import '../api/api_release.dart';
import '../models/universal_bean.dart';
@ -29,8 +30,10 @@ class _ReleaseViewState extends State<ReleaseView> {
List<SongInfo> songInfoList = [];
late File selectedMp3File;
File? selectedCoverFile;
File? selectedMusicFile;
bool isUploading = false;
double uploadProgress = 0.0;
@override
Widget build(BuildContext context) {
@ -353,165 +356,226 @@ class _ReleaseViewState extends State<ReleaseView> {
///
Future<void> _showUploadDialog() async {
TextEditingController songNameController = TextEditingController();
TextEditingController artistNameController = TextEditingController();
// Set default values for song and artist names
songNameController.text = '未知歌曲';
artistNameController.text = '未知歌手';
File selectedCoverImage = File('');
final songNameController = TextEditingController();
final artistNameController = TextEditingController();
await showDialog(
context: context,
builder: (context) => AlertDialog(
shape: RoundedRectangleBorder(
borderRadius:BorderRadius.circular(10),
),
title: const Center(child: Text('上传文件')),
content: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: [
Row(
barrierDismissible: false, //
builder: (context) => StatefulBuilder( // 使 StatefulBuilder
builder: (context, setState) => AlertDialog(
title: const Text('上传音乐'),
content: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('文件'),
IconButton(
onPressed: () async {
selectedMp3File = (await _getMp3File())!;
},
icon: Image.asset(
"assets/img/release_download1.png",
width: 60,
height: 60,
//
ListTile(
leading: const Icon(Icons.music_note),
title: Text(selectedMusicFile?.path.split('/').last ?? '未选择音乐文件'),
trailing: IconButton(
icon: const Icon(Icons.upload_file),
onPressed: () async {
final file = await _pickMusicFile();
if (file != null) {
setState(() => selectedMusicFile = file);
}
},
),
iconSize: 60,
),
],
),
// const SizedBox(height: 10,),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text("封面"),
IconButton(
onPressed: () async {
selectedCoverImage = (await _getImageFromGallery())!;
},
icon: Image.asset(
"assets/img/release_pic1.png",
width: 60,
height: 60,
//
ListTile(
leading: const Icon(Icons.image),
title: Text(selectedCoverFile?.path.split('/').last ?? '未选择封面图片'),
trailing: IconButton(
icon: const Icon(Icons.upload_file),
onPressed: () async {
final file = await _pickImage();
if (file != null) {
setState(() => selectedCoverFile = file);
}
},
),
iconSize: 60,
),
],
),
// const SizedBox(height: 10),
const Text(
'歌名',
),
TextFieldColor(
controller: songNameController,
hintText: '输入歌曲名称'
//
const SizedBox(height: 16),
TextFieldColor(
controller: songNameController,
hintText: '请输入歌曲名称',
),
const SizedBox(height: 8),
TextFieldColor(
controller: artistNameController,
hintText: '请输入歌手名称',
),
//
if (isUploading) _buildProgressIndicator(),
],
),
// const SizedBox(height: 10),
const Text(
'歌手',
),
actions: [
TextButton(
onPressed: isUploading ? null : () => Navigator.pop(context),
child: const Text('取消'),
),
TextFieldColor(
controller: artistNameController,
hintText: '输入歌手名称'
TextButton(
onPressed: isUploading
? null
: () async {
if (_validateInputs(
selectedMusicFile,
selectedCoverFile,
songNameController.text,
artistNameController.text,
)) {
await _performUpload(
songNameController.text,
artistNameController.text,
setState,
);
}
},
child: Text(isUploading ? '上传中...' : '确认上传'),
),
],
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
style: TextButton.styleFrom(
backgroundColor: const Color(0xff429482),
minimumSize: const Size(130, 50),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
),
child: const Text(
"取消",
style: TextStyle(color: Colors.white),
),
),
TextButton(
onPressed: () async {
String enteredSongName = songNameController.text;
String enteredArtistName = artistNameController.text;
if (selectedCoverImage != null && selectedMp3File != null) {
coverImages.add(selectedCoverImage);
songInfoList.add(SongInfo(
songName: enteredSongName,
artistName: enteredArtistName,
));
UniversalBean bean = await ReleaseApi().release(
coverFile:selectedCoverImage,
musicFile: selectedMp3File!,
Authorization: AppData().currentToken,
singerName: enteredArtistName,
name: enteredSongName,
introduce: '0');
Navigator.pop(context);
showDialog(
context: context,
builder: (context) => AlertDialog(
shape: RoundedRectangleBorder(
borderRadius:BorderRadius.circular(10),
),
title: Image.asset("assets/img/correct.png",width: 47,height: 46,),
content: const Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('提交审核成功'),
Text('审核通过后自动发布'),
],
),
actions: [
TextButton(
onPressed: () {
Navigator.pop(context);
},
style: TextButton.styleFrom(
backgroundColor: const Color(0xff429482),
minimumSize: const Size(double.infinity, 50),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0), // Adjust the radius as needed
),
),
child: const Text('确认',style: TextStyle(color: Colors.white),),
),
],
),
);
}
},
style: TextButton.styleFrom(
backgroundColor: const Color(0xff429482),
minimumSize: const Size(130, 45),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
),
child: const Text('确认', style: TextStyle(color: Colors.white),),
),
],
),
);
}
bool _validateInputs(
File? musicFile,
File? coverFile,
String songName,
String artistName,
) {
if (musicFile == null) {
_showErrorMessage('请选择音乐文件');
return false;
}
if (coverFile == null) {
_showErrorMessage('请选择封面图片');
return false;
}
if (songName.isEmpty) {
_showErrorMessage('请输入歌曲名称');
return false;
}
if (artistName.isEmpty) {
_showErrorMessage('请输入歌手名称');
return false;
}
//
if (musicFile.lengthSync() > 10 * 1024 * 1024) { // 10MB
_showErrorMessage('音乐文件大小不能超过10MB');
return false;
}
if (coverFile.lengthSync() > 2 * 1024 * 1024) { // 2MB
_showErrorMessage('封面图片大小不能超过2MB');
return false;
}
return true;
}
Future<void> _performUpload(
String songName,
String artistName,
StateSetter setState,
) async {
setState(() {
isUploading = true;
uploadProgress = 0;
});
try {
final dio = Dio();
//
dio.interceptors.add(InterceptorsWrapper(
onRequest: (options, handler) {
return handler.next(options);
},
onResponse: (response, handler) {
return handler.next(response);
},
onError: (error, handler) {
return handler.next(error);
},
));
String coverFileName = path.basename(selectedCoverFile!.path);
String musicFileName = path.basename(selectedMusicFile!.path);
FormData formData = FormData.fromMap({
'Authorization': AppData().currentToken,
'coverFile': await MultipartFile.fromFile(
selectedCoverFile!.path,
filename: coverFileName,
),
'musicFile': await MultipartFile.fromFile(
selectedMusicFile!.path,
filename: musicFileName,
),
'singerName': artistName,
'name': songName,
'introduce': '暂无简介',
});
final response = await dio.post(
'http://8.210.250.29:10010/musics',
data: formData,
options: Options(
headers: {'Authorization': AppData().currentToken},
),
onSendProgress: (count, total) {
setState(() {
uploadProgress = count / total;
});
},
);
if (response.statusCode == 200) {
_showSuccessDialog();
} else {
_showErrorMessage(response.data['msg'] ?? '上传失败');
}
} catch (e) {
_showErrorMessage('上传失败: $e');
} finally {
setState(() {
isUploading = false;
uploadProgress = 0;
});
}
}
//
Widget _buildProgressIndicator() {
return Column(
children: [
const SizedBox(height: 16),
LinearProgressIndicator(
value: uploadProgress,
backgroundColor: Colors.grey[200],
valueColor: AlwaysStoppedAnimation<Color>(Color(0xff429482)),
),
const SizedBox(height: 8),
Text(
'上传进度: ${(uploadProgress * 100).toStringAsFixed(1)}%',
style: TextStyle(
color: Color(0xff429482),
fontSize: 14,
),
),
],
);
}
Future<File?> _getImageFromGallery([int? index]) async {
final picker = ImagePicker();
@ -589,4 +653,87 @@ class _ReleaseViewState extends State<ReleaseView> {
);
}
//
Future<File?> _pickMusicFile() async {
final result = await FilePicker.platform.pickFiles(
type: FileType.custom,
allowedExtensions: ['mp3'],
);
if (result != null && result.files.isNotEmpty) {
return File(result.files.first.path!);
}
return null;
}
//
Future<File?> _pickImage() async {
final picker = ImagePicker();
final pickedFile = await picker.pickImage(source: ImageSource.gallery);
if (pickedFile != null) {
return File(pickedFile.path);
}
return null;
}
//
void _showErrorMessage(String message) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('提示'),
content: Text(message),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('确定'),
style: TextButton.styleFrom(
backgroundColor: const Color(0xff429482),
foregroundColor: Colors.white,
),
),
],
),
);
}
//
void _showSuccessDialog() {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Image.asset(
"assets/img/correct.png",
width: 47,
height: 46,
),
content: const Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('上传成功'),
Text('审核通过后将自动发布'),
],
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop(); //
//
setState(() {
selectedMusicFile = null;
selectedCoverFile = null;
//
});
},
style: TextButton.styleFrom(
backgroundColor: const Color(0xff429482),
foregroundColor: Colors.white,
),
child: const Text('确定'),
),
],
),
);
}
}
Loading…
Cancel
Save