|
|
@ -8,6 +8,8 @@ import 'package:music_player_miao/widget/text_field.dart';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CommentView extends StatefulWidget {
|
|
|
|
class CommentView extends StatefulWidget {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
_CommentViewState createState() => _CommentViewState();
|
|
|
|
_CommentViewState createState() => _CommentViewState();
|
|
|
|
|
|
|
|
|
|
|
@ -39,23 +41,27 @@ class _CommentViewState extends State<CommentView> {
|
|
|
|
musicId: '1',
|
|
|
|
musicId: '1',
|
|
|
|
pageNo: '0',
|
|
|
|
pageNo: '0',
|
|
|
|
pageSize: '10',
|
|
|
|
pageSize: '10',
|
|
|
|
Authorization: AppData().currentToken);
|
|
|
|
Authorization: AppData().currentToken,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 检查 rows 是否为空
|
|
|
|
|
|
|
|
if (bean1.rows == null) {
|
|
|
|
|
|
|
|
print('No comments found');
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
setState(() {
|
|
|
|
comments = bean1.rows!.map((rows) => rows.content!).toList();
|
|
|
|
comments = bean1.rows!.map((rows) => rows.content ?? 'No content').toList();
|
|
|
|
commentTimes = bean1.rows!.map((rows) => rows.time!).toList();
|
|
|
|
commentTimes = bean1.rows!.map((rows) => rows.time ?? 'Unknown time').toList();
|
|
|
|
commentHeader = bean1.rows!.map((rows) => rows.avatar!).toList();
|
|
|
|
commentHeader = bean1.rows!.map((rows) => rows.avatar ?? 'Default avatar').toList();
|
|
|
|
commentName = bean1.rows!.map((rows) => rows.username!).toList();
|
|
|
|
commentName = bean1.rows!.map((rows) => rows.username ?? 'Anonymous').toList();
|
|
|
|
playlistCount = comments.length;
|
|
|
|
playlistCount = comments.length;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
if (error != null) {
|
|
|
|
|
|
|
|
print('Response data: $error');
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
print('Error fetching songlist data: $error');
|
|
|
|
print('Error fetching songlist data: $error');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -164,17 +170,22 @@ class _CommentViewState extends State<CommentView> {
|
|
|
|
),
|
|
|
|
),
|
|
|
|
IconButton(
|
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
onPressed: () {
|
|
|
|
// setState(() {
|
|
|
|
setState(() {
|
|
|
|
// ascendingOrder = !ascendingOrder;
|
|
|
|
ascendingOrder = !ascendingOrder;
|
|
|
|
// comments.sort((a, b) {
|
|
|
|
|
|
|
|
// int compare = ascendingOrder
|
|
|
|
// 使用时间排序索引列表
|
|
|
|
// ? commentTimes.indexOf(a).compareTo(
|
|
|
|
List<int> sortedIndexes = List<int>.generate(comments.length, (i) => i);
|
|
|
|
// commentTimes.indexOf(b))
|
|
|
|
sortedIndexes.sort((a, b) {
|
|
|
|
// : commentTimes.indexOf(b).compareTo(
|
|
|
|
DateTime timeA = DateTime.parse(commentTimes[a]);
|
|
|
|
// commentTimes.indexOf(a));
|
|
|
|
DateTime timeB = DateTime.parse(commentTimes[b]);
|
|
|
|
// return compare;
|
|
|
|
return ascendingOrder ? timeA.compareTo(timeB) : timeB.compareTo(timeA);
|
|
|
|
// });
|
|
|
|
});
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
comments = [for (var i in sortedIndexes) comments[i]];
|
|
|
|
|
|
|
|
commentTimes = [for (var i in sortedIndexes) commentTimes[i]];
|
|
|
|
|
|
|
|
commentHeader = [for (var i in sortedIndexes) commentHeader[i]];
|
|
|
|
|
|
|
|
commentName = [for (var i in sortedIndexes) commentName[i]];
|
|
|
|
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
icon: Image.asset(
|
|
|
|
icon: Image.asset(
|
|
|
|
ascendingOrder
|
|
|
|
ascendingOrder
|
|
|
@ -284,21 +295,35 @@ class _CommentViewState extends State<CommentView> {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void submitComment() {
|
|
|
|
void submitComment() async {
|
|
|
|
String comment = commentController.text;
|
|
|
|
String comment = commentController.text.trim();
|
|
|
|
if (comment.isNotEmpty) {
|
|
|
|
if (comment.isEmpty) {
|
|
|
|
DateTime currentTime = DateTime.now();
|
|
|
|
print('Comment cannot be empty');
|
|
|
|
String formattedTime = "${currentTime.year}/${currentTime
|
|
|
|
Get.snackbar('错误', '评论不能为空');
|
|
|
|
.month}/${currentTime.day} ${currentTime.hour}:${currentTime.minute}";
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print('Submitting comment with content: $comment');
|
|
|
|
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
try {
|
|
|
|
comments.add(comment);
|
|
|
|
UniversalBean bean = await commentMusic().comment(
|
|
|
|
commentTimes.add(formattedTime);
|
|
|
|
musicId: widget.initialSongIndex,
|
|
|
|
commentName.add(AppData().currentUsername);
|
|
|
|
content: comment,
|
|
|
|
commentHeader.add(AppData().currentAvatar);
|
|
|
|
Authorization: AppData().currentToken,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 处理响应结果
|
|
|
|
|
|
|
|
if (bean.code == 200) {
|
|
|
|
|
|
|
|
print('Comment submitted successfully');
|
|
|
|
commentController.clear();
|
|
|
|
commentController.clear();
|
|
|
|
playlistCount++;
|
|
|
|
_fetchSonglistData(); // 刷新评论列表
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
|
|
|
|
print('Failed to submit comment: ${bean.msg}');
|
|
|
|
|
|
|
|
Get.snackbar('错误', bean.msg ?? '评论提交失败');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
print('Error submitting comment: $error');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|