Skip to content

基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。

fix: episode comments sheet missing animation (#745)

ErBW_sf76c12e65d3f
diff --git a/lib/pages/player/episode_comments_sheet.dart b/lib/pages/player/episode_comments_sheet.dart
index 5dd8e09a..49b89d21 100644
--- a/lib/pages/player/episode_comments_sheet.dart
+++ b/lib/pages/player/episode_comments_sheet.dart
@@ -1,3 +1,4 @@
+import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
@@ -6,48 +7,66 @@ import 'package:kazumi/bean/dialog/dialog_helper.dart';
import 'package:kazumi/pages/info/info_controller.dart';
import 'package:kazumi/bean/card/episode_comments_card.dart';
-class EpisodeCommentsSheet extends StatefulWidget {
- const EpisodeCommentsSheet({super.key, required this.episode});
+class EpisodeInfo extends InheritedWidget {
+ /// This widget receives changes of episode and notify it's child,
+ /// trigger [didChangeDependencies] of it's child.
+ const EpisodeInfo({super.key, required this.episode, required super.child});
final int episode;
+ @override
+ bool updateShouldNotify(covariant InheritedWidget oldWidget) => true;
+
+ static EpisodeInfo? of(BuildContext context) {
+ return context.dependOnInheritedWidgetOfExactType<EpisodeInfo>();
+ }
+}
+
+class EpisodeCommentsSheet extends StatefulWidget {
+ const EpisodeCommentsSheet({super.key});
+
@override
State<EpisodeCommentsSheet> createState() => _EpisodeCommentsSheetState();
}
class _EpisodeCommentsSheetState extends State<EpisodeCommentsSheet> {
final infoController = Modular.get<InfoController>();
- bool isLoading = false;
bool commentsQueryTimeout = false;
+ final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
+ GlobalKey<RefreshIndicatorState>();
+
+ /// episode input by [showEpisodeSelection]
+ int ep = 0;
@override
void initState() {
super.initState();
- if (infoController.episodeCommentsList.isEmpty) {
- setState(() {
- isLoading = true;
- });
- loadComments(widget.episode);
- }
}
Future<void> loadComments(int episode) async {
commentsQueryTimeout = false;
- infoController
+ await infoController
.queryBangumiEpisodeCommentsByID(infoController.bangumiItem.id, episode)
.then((_) {
if (infoController.episodeCommentsList.isEmpty && mounted) {
setState(() {
commentsQueryTimeout = true;
- isLoading = false;
});
}
- if (infoController.episodeCommentsList.isNotEmpty && mounted) {
- setState(() {
- isLoading = false;
- });
+ });
+ }
+
+ @override
+ void didChangeDependencies() {
+ ep = 0;
+ // wait until currentState is not null
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ if (infoController.episodeCommentsList.isEmpty) {
+ // trigger RefreshIndicator onRefresh and show animation
+ _refreshIndicatorKey.currentState?.show();
}
});
+ super.didChangeDependencies();
}
@override
@@ -57,19 +76,19 @@ class _EpisodeCommentsSheetState extends State<EpisodeCommentsSheet> {
Widget get episodeCommentsBody {
return CustomScrollView(
- // Scrollbars' movement is not linear so hide it.
- scrollBehavior: const ScrollBehavior().copyWith(scrollbars: false),
+ scrollBehavior: const ScrollBehavior().copyWith(
+ // Scrollbars' movement is not linear so hide it.
+ scrollbars: false,
+ // Enable mouse drag to refresh
+ dragDevices: {
+ PointerDeviceKind.mouse,
+ PointerDeviceKind.touch,
+ },
+ ),
slivers: [
SliverPadding(
padding: const EdgeInsets.fromLTRB(4, 0, 4, 4),
sliver: Observer(builder: (context) {
- if (isLoading) {
- return const SliverFillRemaining(
- child: Center(
- child: CircularProgressIndicator(),
- ),
- );
- }
if (commentsQueryTimeout) {
return const SliverFillRemaining(
child: Center(
@@ -187,14 +206,11 @@ class _EpisodeCommentsSheetState extends State<EpisodeCommentsSheet> {
KazumiDialog.showToast(message: '请输入集数');
return;
}
- final ep = int.tryParse(textController.text) ?? 0;
+ ep = int.tryParse(textController.text) ?? 0;
if (ep == 0) {
return;
}
- setState(() {
- isLoading = true;
- });
- loadComments(ep);
+ _refreshIndicatorKey.currentState?.show();
KazumiDialog.dismiss();
},
child: const Text('刷新'),
@@ -207,10 +223,18 @@ class _EpisodeCommentsSheetState extends State<EpisodeCommentsSheet> {
@override
Widget build(BuildContext context) {
+ final int episode = EpisodeInfo.of(context)!.episode;
return Scaffold(
- body: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [commentsInfo, Expanded(child: episodeCommentsBody)],
+ body: RefreshIndicator(
+ key: _refreshIndicatorKey,
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [commentsInfo, Expanded(child: episodeCommentsBody)],
+ ),
+ onRefresh: () async {
+ await loadComments(ep == 0 ? episode : ep);
+ setState(() {});
+ },
),
);
}
diff --git a/lib/pages/video/video_page.dart b/lib/pages/video/video_page.dart
index 1ff605fb..1d47e750 100644
--- a/lib/pages/video/video_page.dart
+++ b/lib/pages/video/video_page.dart
@@ -74,8 +74,8 @@ class _VideoPageState extends State<VideoPage>
windowManager.addListener(this);
// Check fullscreen when enter video page
// in case user use system controls to enter fullscreen outside video page
- tabController = TabController(length: 2, vsync: this);
videoPageController.isDesktopFullscreen();
+ tabController = TabController(length: 2, vsync: this);
observerController = GridObserverController(controller: scrollController);
animation = AnimationController(
duration: const Duration(milliseconds: 100),
@@ -206,12 +206,6 @@ class _VideoPageState extends State<VideoPage>
videoPageController.loading = true;
infoController.episodeInfo.reset();
infoController.episodeCommentsList.clear();
- // Query comments when tab is visible
- // We need lazy load comments to avoid unnecessary API requests
- // so we only query comments when the tab is visible rather than video is loaded
- if (tabController.index == 1) {
- infoController.queryBangumiEpisodeCommentsByID(infoController.bangumiItem.id, episode);
- }
await playerController.stop();
await videoPageController.changeEpisode(episode,
currentRoad: currentRoad, offset: offset);
@@ -897,7 +891,10 @@ class _VideoPageState extends State<VideoPage>
],
),
),
- EpisodeCommentsSheet(episode: episodeNum),
+ EpisodeInfo(
+ episode: episodeNum,
+ child: EpisodeCommentsSheet(),
+ ),
],
),
),