mod: 接口整理、增加up粉丝请求

This commit is contained in:
guozhigq
2023-04-21 16:07:34 +08:00
parent 171c16a4f9
commit 3aee691d00
10 changed files with 210 additions and 108 deletions

View File

@ -1,6 +1,6 @@
import 'package:get/get.dart';
import 'package:pilipala/http/api.dart';
import 'package:pilipala/http/init.dart';
import 'package:pilipala/http/user.dart';
import 'package:pilipala/http/video.dart';
import 'package:pilipala/models/video_detail_res.dart';
import 'package:pilipala/pages/video/detail/controller.dart';
@ -20,6 +20,12 @@ class VideoIntroController extends GetxController {
// 视频详情 请求返回
Rx<VideoDetailData> videoDetail = VideoDetailData().obs;
// 请求返回的信息
String responseMsg = '请求异常';
// up主粉丝数
Map userStat = {'follower': '-'};
@override
void onInit() {
super.onInit();
@ -36,17 +42,28 @@ class VideoIntroController extends GetxController {
}
}
Future queryVideoDetail() async {
var res = await Request().get(Api.videoDetail, data: {
'aid': aid,
});
VideoDetailResponse result = VideoDetailResponse.fromJson(res.data);
videoDetail.value = result.data!;
Get.find<VideoDetailController>().tabs.value = [
'简介',
'评论 ${result.data!.stat!.reply}'
];
// await Future.delayed(const Duration(seconds: 3));
return true;
// 获取视频简介
Future queryVideoIntro() async {
var result = await VideoHttp.videoIntro(aid);
if (result['status']) {
videoDetail.value = result['data']!;
Get.find<VideoDetailController>().tabs.value = [
'简介',
'评论 ${result['data']!.stat!.reply}'
];
} else {
responseMsg = result['msg'];
}
// 获取到粉丝数再返回
await queryUserStat();
return result;
}
// 获取up主粉丝数
Future queryUserStat() async {
var result = await UserHttp.userStat(videoDetail.value.owner!.mid);
if (result['status']) {
userStat = result['data'];
}
}
}

View File

@ -1,6 +1,7 @@
import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'package:pilipala/common/constants.dart';
import 'package:pilipala/common/widgets/http_error.dart';
import 'package:pilipala/pages/video/detail/widgets/expandable_section.dart';
import 'package:pilipala/common/widgets/network_img_layer.dart';
import 'package:pilipala/common/widgets/stat/danmu.dart';
@ -43,27 +44,29 @@ class _VideoIntroPanelState extends State<VideoIntroPanel>
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: videoIntroController.queryVideoDetail(),
future: videoIntroController.queryVideoIntro(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.data) {
if (snapshot.data['status']) {
// 请求成功
// return _buildView(context, false, videoDetail);
return VideoInfo(loadingStatus: false, videoDetail: videoDetail);
return VideoInfo(
loadingStatus: false,
videoDetail: videoDetail,
videoIntroController: videoIntroController);
} else {
// 请求错误
return Center(
child: IconButton(
icon: const Icon(Icons.refresh),
onPressed: () {
setState(() {});
},
),
return HttpError(
errMsg: snapshot.data['msg'],
fn: () => setState(() {}),
);
}
} else {
// return _buildView(context, true, videoDetail);
return VideoInfo(loadingStatus: true, videoDetail: videoDetail);
return VideoInfo(
loadingStatus: true,
videoDetail: videoDetail,
videoIntroController: videoIntroController);
}
},
);
@ -90,8 +93,13 @@ class _VideoIntroPanelState extends State<VideoIntroPanel>
class VideoInfo extends StatefulWidget {
bool loadingStatus = false;
VideoDetailData? videoDetail;
VideoIntroController? videoIntroController;
VideoInfo({Key? key, required this.loadingStatus, this.videoDetail})
VideoInfo(
{Key? key,
required this.loadingStatus,
this.videoDetail,
this.videoIntroController})
: super(key: key);
@override
@ -150,19 +158,17 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
? widget.videoDetail!.owner!.name
: videoItem['owner'].name),
const SizedBox(height: 2),
// Text.rich(
// TextSpan(
// style: TextStyle(
// color: Theme.of(context)
// .colorScheme
// .outline,
// fontSize: 11),
// children: const [
// TextSpan(text: '2.6万粉丝'),
// TextSpan(text: ' '),
// TextSpan(text: '2.6万粉丝'),
// ]),
// ),
Text(
widget.loadingStatus
? '- 粉丝'
: '${Utils.numFormat(widget.videoIntroController!.userStat['follower'])}粉丝',
style: TextStyle(
fontSize: Theme.of(context)
.textTheme
.labelSmall!
.fontSize,
color: Theme.of(context).colorScheme.outline),
)
]),
const Spacer(),
AnimatedOpacity(