fix: 合集页数据容错处理(cid无法对应)

This commit is contained in:
orz12
2024-02-29 20:56:50 +08:00
parent eae17a2f79
commit fd41b5cf2c

View File

@@ -1,3 +1,5 @@
import 'dart:math';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:PiliPalaX/models/video_detail_res.dart'; import 'package:PiliPalaX/models/video_detail_res.dart';
@@ -23,9 +25,9 @@ class SeasonPanel extends StatefulWidget {
} }
class _SeasonPanelState extends State<SeasonPanel> { class _SeasonPanelState extends State<SeasonPanel> {
late List<EpisodeItem> episodes; List<EpisodeItem>? episodes;
late int cid; late int cid;
late int currentIndex; int currentIndex = 0;
final String heroTag = Get.arguments['heroTag']; final String heroTag = Get.arguments['heroTag'];
late VideoDetailController _videoDetailController; late VideoDetailController _videoDetailController;
final ScrollController _scrollController = ScrollController(); final ScrollController _scrollController = ScrollController();
@@ -50,16 +52,19 @@ class _SeasonPanelState extends State<SeasonPanel> {
} }
} }
} }
if (episodes == null) {
return;
}
/// 取对应 season_id 的 episodes /// 取对应 season_id 的 episodes
// episodes = widget.ugcSeason.sections! // episodes = widget.ugcSeason.sections!
// .firstWhere((e) => e.seasonId == widget.ugcSeason.id) // .firstWhere((e) => e.seasonId == widget.ugcSeason.id)
// .episodes!; // .episodes!;
currentIndex = episodes.indexWhere((EpisodeItem e) => e.cid == cid); currentIndex = episodes!.indexWhere((EpisodeItem e) => e.cid == cid);
_videoDetailController.cid.listen((int p0) { _videoDetailController.cid.listen((int p0) {
cid = p0; cid = p0;
setState(() {}); setState(() {});
currentIndex = episodes.indexWhere((EpisodeItem e) => e.cid == cid); currentIndex = episodes!.indexWhere((EpisodeItem e) => e.cid == cid);
}); });
} }
@@ -82,6 +87,9 @@ class _SeasonPanelState extends State<SeasonPanel> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (episodes == null) {
return const SizedBox();
}
return Builder(builder: (BuildContext context) { return Builder(builder: (BuildContext context) {
return Container( return Container(
margin: const EdgeInsets.only( margin: const EdgeInsets.only(
@@ -115,10 +123,11 @@ class _SeasonPanelState extends State<SeasonPanel> {
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text( Text(
'合集(${episodes.length}', '合集(${episodes!.length}',
style: Theme.of(context).textTheme.titleMedium, style: Theme.of(context).textTheme.titleMedium,
), ),
IconButton( IconButton(
tooltip: '关闭',
icon: const Icon(Icons.close), icon: const Icon(Icons.close),
onPressed: () => Navigator.pop(context), onPressed: () => Navigator.pop(context),
), ),
@@ -136,15 +145,15 @@ class _SeasonPanelState extends State<SeasonPanel> {
bottom: MediaQuery.of(context).padding.bottom), bottom: MediaQuery.of(context).padding.bottom),
child: Material( child: Material(
child: ScrollablePositionedList.builder( child: ScrollablePositionedList.builder(
itemCount: episodes.length, itemCount: episodes!.length,
itemBuilder: (BuildContext context, int index) => itemBuilder: (BuildContext context, int index) =>
ListTile( ListTile(
onTap: () => onTap: () =>
changeFucCall(episodes[index], index), changeFucCall(episodes![index], index),
dense: false, dense: false,
leading: index == currentIndex leading: index == currentIndex
? Image.asset( ? Image.asset(
'assets/images/live.gif', 'assets/images/live.png',
color: Theme.of(context) color: Theme.of(context)
.colorScheme .colorScheme
.primary, .primary,
@@ -152,7 +161,7 @@ class _SeasonPanelState extends State<SeasonPanel> {
) )
: null, : null,
title: Text( title: Text(
episodes[index].title!, episodes![index].title!,
style: TextStyle( style: TextStyle(
fontSize: 14, fontSize: 14,
color: index == currentIndex color: index == currentIndex
@@ -161,6 +170,9 @@ class _SeasonPanelState extends State<SeasonPanel> {
.colorScheme .colorScheme
.onSurface, .onSurface,
), ),
semanticsLabel: index == currentIndex
? '当前播放:${episodes![index].title!}'
: null,
), ),
), ),
itemScrollController: itemScrollController, itemScrollController: itemScrollController,
@@ -192,13 +204,16 @@ class _SeasonPanelState extends State<SeasonPanel> {
), ),
const SizedBox(width: 10), const SizedBox(width: 10),
Text( Text(
'${currentIndex + 1}/${episodes.length}', '${currentIndex + 1}/${episodes!.length}',
style: Theme.of(context).textTheme.labelMedium, style: Theme.of(context).textTheme.labelMedium,
semanticsLabel:
'${currentIndex + 1}集,共${episodes!.length}',
), ),
const SizedBox(width: 6), const SizedBox(width: 6),
const Icon( const Icon(
Icons.arrow_forward_ios_outlined, Icons.arrow_forward_ios_outlined,
size: 13, size: 13,
semanticLabel: '查看',
) )
], ],
), ),