From fd41b5cf2c51ad1cbcd760fdb904d50923066d6d Mon Sep 17 00:00:00 2001 From: orz12 Date: Thu, 29 Feb 2024 20:56:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=90=88=E9=9B=86=E9=A1=B5=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=AE=B9=E9=94=99=E5=A4=84=E7=90=86=EF=BC=88cid?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=AF=B9=E5=BA=94=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../detail/introduction/widgets/season.dart | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/lib/pages/video/detail/introduction/widgets/season.dart b/lib/pages/video/detail/introduction/widgets/season.dart index a99c254b..83dbe93c 100644 --- a/lib/pages/video/detail/introduction/widgets/season.dart +++ b/lib/pages/video/detail/introduction/widgets/season.dart @@ -1,3 +1,5 @@ +import 'dart:math'; + import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:PiliPalaX/models/video_detail_res.dart'; @@ -23,9 +25,9 @@ class SeasonPanel extends StatefulWidget { } class _SeasonPanelState extends State { - late List episodes; + List? episodes; late int cid; - late int currentIndex; + int currentIndex = 0; final String heroTag = Get.arguments['heroTag']; late VideoDetailController _videoDetailController; final ScrollController _scrollController = ScrollController(); @@ -50,16 +52,19 @@ class _SeasonPanelState extends State { } } } + if (episodes == null) { + return; + } /// 取对应 season_id 的 episodes // episodes = widget.ugcSeason.sections! // .firstWhere((e) => e.seasonId == widget.ugcSeason.id) // .episodes!; - currentIndex = episodes.indexWhere((EpisodeItem e) => e.cid == cid); + currentIndex = episodes!.indexWhere((EpisodeItem e) => e.cid == cid); _videoDetailController.cid.listen((int p0) { cid = p0; 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 { @override Widget build(BuildContext context) { + if (episodes == null) { + return const SizedBox(); + } return Builder(builder: (BuildContext context) { return Container( margin: const EdgeInsets.only( @@ -115,10 +123,11 @@ class _SeasonPanelState extends State { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( - '合集(${episodes.length})', + '合集(${episodes!.length})', style: Theme.of(context).textTheme.titleMedium, ), IconButton( + tooltip: '关闭', icon: const Icon(Icons.close), onPressed: () => Navigator.pop(context), ), @@ -136,15 +145,15 @@ class _SeasonPanelState extends State { bottom: MediaQuery.of(context).padding.bottom), child: Material( child: ScrollablePositionedList.builder( - itemCount: episodes.length, + itemCount: episodes!.length, itemBuilder: (BuildContext context, int index) => ListTile( onTap: () => - changeFucCall(episodes[index], index), + changeFucCall(episodes![index], index), dense: false, leading: index == currentIndex ? Image.asset( - 'assets/images/live.gif', + 'assets/images/live.png', color: Theme.of(context) .colorScheme .primary, @@ -152,7 +161,7 @@ class _SeasonPanelState extends State { ) : null, title: Text( - episodes[index].title!, + episodes![index].title!, style: TextStyle( fontSize: 14, color: index == currentIndex @@ -161,6 +170,9 @@ class _SeasonPanelState extends State { .colorScheme .onSurface, ), + semanticsLabel: index == currentIndex + ? '当前播放:${episodes![index].title!}' + : null, ), ), itemScrollController: itemScrollController, @@ -192,13 +204,16 @@ class _SeasonPanelState extends State { ), const SizedBox(width: 10), Text( - '${currentIndex + 1}/${episodes.length}', + '${currentIndex + 1}/${episodes!.length}', style: Theme.of(context).textTheme.labelMedium, + semanticsLabel: + '第${currentIndex + 1}集,共${episodes!.length}集', ), const SizedBox(width: 6), const Icon( Icons.arrow_forward_ios_outlined, size: 13, + semanticLabel: '查看', ) ], ),