评论数据渲染
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:pilipala/http/reply.dart';
|
||||
import 'package:pilipala/models/video/reply/data.dart';
|
||||
|
||||
class VideoReplyController extends GetxController {
|
||||
// 视频aid
|
||||
@ -13,5 +14,10 @@ class VideoReplyController extends GetxController {
|
||||
|
||||
Future queryReplyList() async {
|
||||
var res = await ReplyHttp.replyList(oid: aid, pageNum: 1, type: 1);
|
||||
if (res['status']) {
|
||||
res['data'] = ReplyData.fromJson(res['data']);
|
||||
print(res['data'].replies);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:pilipala/common/skeleton/video_card_h.dart';
|
||||
import 'package:pilipala/common/widgets/http_error.dart';
|
||||
import 'package:pilipala/common/widgets/reply_item.dart';
|
||||
import 'controller.dart';
|
||||
|
||||
class VideoReplyPanel extends StatefulWidget {
|
||||
const VideoReplyPanel({super.key});
|
||||
@ -8,10 +13,46 @@ class VideoReplyPanel extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _VideoReplyPanelState extends State<VideoReplyPanel> {
|
||||
final VideoReplyController _videoReplyController =
|
||||
Get.put(VideoReplyController(), tag: Get.arguments['heroTag']);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const SliverToBoxAdapter(
|
||||
child: Text('评论'),
|
||||
return FutureBuilder(
|
||||
future: _videoReplyController.queryReplyList(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
if (snapshot.data['status']) {
|
||||
List<dynamic> replies = snapshot.data['data'].replies;
|
||||
replies.addAll(snapshot.data['data'].topReplies);
|
||||
// 请求成功
|
||||
return SliverList(
|
||||
delegate: SliverChildBuilderDelegate((context, index) {
|
||||
if (index == replies.length) {
|
||||
return SizedBox(height: MediaQuery.of(context).padding.bottom);
|
||||
} else {
|
||||
return ReplyItem(
|
||||
replyItem: replies[index],
|
||||
isUp:
|
||||
replies[index].mid == snapshot.data['data'].upper.mid);
|
||||
}
|
||||
}, childCount: replies.length + 1));
|
||||
} else {
|
||||
// 请求错误
|
||||
return HttpError(
|
||||
errMsg: snapshot.data['msg'],
|
||||
fn: () => setState(() {}),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// 骨架屏
|
||||
return SliverList(
|
||||
delegate: SliverChildBuilderDelegate((context, index) {
|
||||
return const VideoCardHSkeleton();
|
||||
}, childCount: 5),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user