mod: 相关推荐视频开发、页面跳转Hero、一些字段修改
This commit is contained in:
@ -1,6 +1,9 @@
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class VideoDetailController extends GetxController {
|
||||
// tabs
|
||||
RxList<String> tabs = <String>['简介', '评论'].obs;
|
||||
|
||||
// 视频aid
|
||||
String aid = Get.parameters['aid']!;
|
||||
|
||||
@ -14,6 +17,7 @@ class VideoDetailController extends GetxController {
|
||||
RxBool isLoading = false.obs;
|
||||
|
||||
String heroTag = '';
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
|
@ -2,6 +2,7 @@ import 'package:get/get.dart';
|
||||
import 'package:pilipala/http/api.dart';
|
||||
import 'package:pilipala/http/init.dart';
|
||||
import 'package:pilipala/models/video_detail_res.dart';
|
||||
import 'package:pilipala/pages/video/detail/controller.dart';
|
||||
|
||||
class VideoIntroController extends GetxController {
|
||||
// 视频aid
|
||||
@ -41,6 +42,10 @@ class VideoIntroController extends GetxController {
|
||||
});
|
||||
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;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
library video_detail_introduction;
|
||||
library video_intro_panel;
|
||||
|
||||
export './controller.dart';
|
||||
export './view.dart';
|
||||
|
@ -1,4 +1,3 @@
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pilipala/common/constants.dart';
|
||||
@ -17,11 +16,16 @@ class VideoIntroPanel extends StatefulWidget {
|
||||
State<VideoIntroPanel> createState() => _VideoIntroPanelState();
|
||||
}
|
||||
|
||||
class _VideoIntroPanelState extends State<VideoIntroPanel> {
|
||||
class _VideoIntroPanelState extends State<VideoIntroPanel>
|
||||
with AutomaticKeepAliveClientMixin {
|
||||
final VideoIntroController videoIntroController =
|
||||
Get.put(VideoIntroController());
|
||||
VideoDetailData? videoDetail;
|
||||
|
||||
// 添加页面缓存
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@ -42,10 +46,10 @@ class _VideoIntroPanelState extends State<VideoIntroPanel> {
|
||||
future: videoIntroController.queryVideoDetail(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
print(snapshot.data);
|
||||
if (snapshot.data) {
|
||||
// 请求成功
|
||||
return _buildView(context, false, videoDetail);
|
||||
// return _buildView(context, false, videoDetail);
|
||||
return VideoInfo(loadingStatus: false, videoDetail: videoDetail);
|
||||
} else {
|
||||
// 请求错误
|
||||
return Center(
|
||||
@ -58,7 +62,8 @@ class _VideoIntroPanelState extends State<VideoIntroPanel> {
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return _buildView(context, true, videoDetail);
|
||||
// return _buildView(context, true, videoDetail);
|
||||
return VideoInfo(loadingStatus: true, videoDetail: videoDetail);
|
||||
}
|
||||
},
|
||||
);
|
||||
@ -320,7 +325,7 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
|
||||
),
|
||||
),
|
||||
_actionGrid(context),
|
||||
const SizedBox(height: 5),
|
||||
// const SizedBox(height: 5),
|
||||
],
|
||||
)
|
||||
: const Center(child: CircularProgressIndicator()),
|
||||
|
0
lib/pages/video/detail/player/controller.dart
Normal file
0
lib/pages/video/detail/player/controller.dart
Normal file
4
lib/pages/video/detail/player/index.dart
Normal file
4
lib/pages/video/detail/player/index.dart
Normal file
@ -0,0 +1,4 @@
|
||||
library video_player;
|
||||
|
||||
export './controller.dart';
|
||||
export './view.dart';
|
0
lib/pages/video/detail/player/view.dart
Normal file
0
lib/pages/video/detail/player/view.dart
Normal file
31
lib/pages/video/detail/related/controller.dart
Normal file
31
lib/pages/video/detail/related/controller.dart
Normal file
@ -0,0 +1,31 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:get/get.dart';
|
||||
import 'package:pilipala/http/video.dart';
|
||||
import 'package:pilipala/models/model_hot_video_item.dart';
|
||||
|
||||
class ReleatedController extends GetxController {
|
||||
// 视频aid
|
||||
String aid = Get.parameters['aid']!;
|
||||
// 推荐视频列表
|
||||
List relatedVideoList = [];
|
||||
|
||||
Future<dynamic> queryVideoRecommend() async {
|
||||
try {
|
||||
var res = await VideoHttp.videoRecommend({'aid': aid});
|
||||
List<HotVideoItemModel> list = [];
|
||||
try {
|
||||
for (var i in res.data['data']) {
|
||||
list.add(HotVideoItemModel.fromJson(i));
|
||||
}
|
||||
relatedVideoList = list;
|
||||
} catch (err) {
|
||||
return err.toString();
|
||||
}
|
||||
|
||||
return res.data['data'];
|
||||
} catch (err) {
|
||||
return err.toString();
|
||||
}
|
||||
}
|
||||
}
|
4
lib/pages/video/detail/related/index.dart
Normal file
4
lib/pages/video/detail/related/index.dart
Normal file
@ -0,0 +1,4 @@
|
||||
library releated_video_panel;
|
||||
|
||||
export './controller.dart';
|
||||
export './view.dart';
|
49
lib/pages/video/detail/related/view.dart
Normal file
49
lib/pages/video/detail/related/view.dart
Normal file
@ -0,0 +1,49 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:pilipala/common/widgets/video_card_h.dart';
|
||||
import './controller.dart';
|
||||
|
||||
class RelatedVideoPanel extends StatefulWidget {
|
||||
const RelatedVideoPanel({super.key});
|
||||
|
||||
@override
|
||||
State<RelatedVideoPanel> createState() => _RelatedVideoPanelState();
|
||||
}
|
||||
|
||||
class _RelatedVideoPanelState extends State<RelatedVideoPanel> {
|
||||
final ReleatedController _releatedController = Get.put(ReleatedController());
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder(
|
||||
future: _releatedController.queryVideoRecommend(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
if (snapshot.data!.isNotEmpty) {
|
||||
// 请求成功
|
||||
List videoList = _releatedController.relatedVideoList;
|
||||
return SliverList(
|
||||
delegate: SliverChildBuilderDelegate((context, index) {
|
||||
if (index == videoList.length) {
|
||||
return SizedBox(height: MediaQuery.of(context).padding.bottom);
|
||||
} else {
|
||||
return VideoCardH(
|
||||
videoItem: videoList[index],
|
||||
);
|
||||
}
|
||||
}, childCount: videoList.length + 1));
|
||||
} else {
|
||||
// 请求错误
|
||||
return const Center(
|
||||
child: Text('出错了'),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return const SliverToBoxAdapter(
|
||||
child: Text('请求中'),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:pilipala/common/widgets/network_img_layer.dart';
|
||||
import 'package:pilipala/pages/video/detail/controller.dart';
|
||||
import 'package:pilipala/pages/video/detail/introduction/index.dart';
|
||||
import 'package:pilipala/pages/video/detail/related/index.dart';
|
||||
|
||||
class VideoDetailPage extends StatefulWidget {
|
||||
const VideoDetailPage({Key? key}) : super(key: key);
|
||||
@ -15,12 +16,10 @@ class _VideoDetailPageState extends State<VideoDetailPage> {
|
||||
final VideoDetailController videoDetailController =
|
||||
Get.put(VideoDetailController());
|
||||
|
||||
final _tabs = <String>['简介', '评论'];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return DefaultTabController(
|
||||
length: _tabs.length, // tab的数量.
|
||||
length: videoDetailController.tabs.length, // tab的数量.
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
bottom: false,
|
||||
@ -80,14 +79,16 @@ class _VideoDetailPageState extends State<VideoDetailPage> {
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Container(
|
||||
width: 180,
|
||||
width: 280,
|
||||
margin: const EdgeInsets.only(left: 20),
|
||||
child: TabBar(
|
||||
splashBorderRadius: BorderRadius.circular(6),
|
||||
dividerColor: Colors.transparent,
|
||||
tabs: _tabs
|
||||
.map((String name) => Tab(text: name))
|
||||
.toList(),
|
||||
child: Obx(
|
||||
() => TabBar(
|
||||
splashBorderRadius: BorderRadius.circular(6),
|
||||
dividerColor: Colors.transparent,
|
||||
tabs: videoDetailController.tabs
|
||||
.map((String name) => Tab(text: name))
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
// 弹幕开关
|
||||
@ -117,6 +118,14 @@ class _VideoDetailPageState extends State<VideoDetailPage> {
|
||||
context),
|
||||
),
|
||||
const VideoIntroPanel(),
|
||||
SliverToBoxAdapter(
|
||||
child: Divider(
|
||||
color:
|
||||
Theme.of(context).dividerColor.withOpacity(0.1),
|
||||
),
|
||||
),
|
||||
const SliverPadding(padding: EdgeInsets.only(bottom: 5)),
|
||||
const RelatedVideoPanel(),
|
||||
],
|
||||
);
|
||||
}),
|
||||
|
Reference in New Issue
Block a user