handle sub url

Closes #995

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-08-11 21:11:28 +08:00
parent 17b7eb7e0f
commit be5a1af040
9 changed files with 122 additions and 181 deletions

View File

@@ -3,6 +3,7 @@ import 'package:PiliPlus/common/widgets/image/network_img_layer.dart';
import 'package:PiliPlus/common/widgets/loading_widget/http_error.dart';
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
import 'package:PiliPlus/http/loading_state.dart';
import 'package:PiliPlus/models_new/sub/sub/list.dart';
import 'package:PiliPlus/models_new/sub/sub_detail/media.dart';
import 'package:PiliPlus/pages/subscription_detail/controller.dart';
import 'package:PiliPlus/pages/subscription_detail/widget/sub_video_card.dart';
@@ -17,6 +18,21 @@ class SubDetailPage extends StatefulWidget {
@override
State<SubDetailPage> createState() => _SubDetailPageState();
static void toSubDetailPage(
int id, {
String? heroTag,
SubItemModel? subInfo,
}) {
Get.toNamed(
'/subDetail',
arguments: {
'id': id,
'subInfo': subInfo,
'heroTag': heroTag,
},
);
}
}
class _SubDetailPageState extends State<SubDetailPage> {
@@ -39,7 +55,7 @@ class _SubDetailPageState extends State<SubDetailPage> {
controller: _subDetailController.scrollController,
physics: const AlwaysScrollableScrollPhysics(),
slivers: [
_buildAppBar(theme, padding),
_appBar(theme, padding),
SliverPadding(
padding: EdgeInsets.only(
top: 7,
@@ -91,11 +107,37 @@ class _SubDetailPageState extends State<SubDetailPage> {
};
}
Widget _buildAppBar(ThemeData theme, EdgeInsets padding) {
Widget _appBar(ThemeData theme, EdgeInsets padding) {
final info = _subDetailController.subInfo;
if (info != null) return _buildAppBar(theme, padding, info);
return Obx(() {
return switch (_subDetailController.loadingState.value) {
Loading() || Error() => const SliverAppBar(),
Success() => _buildAppBar(
theme,
padding,
_subDetailController.subInfo!,
),
};
});
}
Widget _buildAppBar(ThemeData theme, EdgeInsets padding, SubItemModel info) {
final style = TextStyle(
fontSize: 12.5,
color: theme.colorScheme.outline,
);
Widget cover = NetworkImgLayer(
width: 176,
height: 110,
src: info.cover,
);
if (_subDetailController.heroTag != null) {
cover = Hero(
tag: _subDetailController.heroTag!,
child: cover,
);
}
return SliverAppBar.medium(
expandedHeight: kToolbarHeight + 132,
pinned: true,
@@ -103,16 +145,14 @@ class _SubDetailPageState extends State<SubDetailPage> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
_subDetailController.subInfo.title!,
info.title!,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: theme.textTheme.titleMedium,
),
Obx(
() => Text(
'${_subDetailController.mediaCount.value}条视频',
style: theme.textTheme.labelMedium,
),
Text(
'${info.mediaCount}条视频',
style: theme.textTheme.labelMedium,
),
],
),
@@ -135,21 +175,14 @@ class _SubDetailPageState extends State<SubDetailPage> {
spacing: 12,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Hero(
tag: _subDetailController.heroTag,
child: NetworkImgLayer(
width: 176,
height: 110,
src: _subDetailController.subInfo.cover,
),
),
cover,
Expanded(
child: Column(
spacing: 4,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
_subDetailController.subInfo.title!,
info.title!,
style: TextStyle(
fontSize: theme.textTheme.titleMedium!.fontSize,
fontWeight: FontWeight.bold,
@@ -158,32 +191,19 @@ class _SubDetailPageState extends State<SubDetailPage> {
GestureDetector(
onTap: () {
Get.toNamed(
'/member?mid=${_subDetailController.subInfo.upper!.mid}',
'/member?mid=${info.upper!.mid}',
);
},
child: Text(
_subDetailController.subInfo.upper!.name!,
info.upper!.name!,
style: TextStyle(color: theme.colorScheme.primary),
),
),
const Spacer(),
Obx(
() {
final mediaCount =
_subDetailController.mediaCount.value;
return mediaCount == 0
? const SizedBox.shrink()
: Text(
'$mediaCount条视频',
style: style,
);
},
),
Obx(
() => Text(
'${NumUtil.numFormat(_subDetailController.playCount.value)}次播放',
style: style,
),
Text('${info.mediaCount}条视频', style: style),
Text(
'${NumUtil.numFormat(info.viewCount ?? info.cntInfo?.play)}次播放',
style: style,
),
],
),