Skip to content

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

fix memory leak caused by tab controller

Prediditfd0be0239332
diff --git a/lib/pages/collect/collect_page.dart b/lib/pages/collect/collect_page.dart
index a9e7cc9d..dee1de45 100644
--- a/lib/pages/collect/collect_page.dart
+++ b/lib/pages/collect/collect_page.dart
@@ -24,7 +24,7 @@ class _CollectPageState extends State<CollectPage>
with SingleTickerProviderStateMixin {
final CollectController collectController = Modular.get<CollectController>();
late NavigationBarState navigationBarState;
- TabController? controller;
+ TabController? tabController;
bool showDelete = false;
bool syncCollectiblesing = false;
Box setting = GStorage.setting;
@@ -38,11 +38,17 @@ class _CollectPageState extends State<CollectPage>
void initState() {
super.initState();
collectController.loadCollectibles();
- controller = TabController(vsync: this, length: tabs.length);
+ tabController = TabController(vsync: this, length: tabs.length);
navigationBarState =
Provider.of<NavigationBarState>(context, listen: false);
}
+ @override
+ void dispose() {
+ tabController?.dispose();
+ super.dispose();
+ }
+
final List<Tab> tabs = const <Tab>[
Tab(text: '在看'),
Tab(text: '想看'),
@@ -67,7 +73,7 @@ class _CollectPageState extends State<CollectPage>
needTopOffset: false,
toolbarHeight: 104,
bottom: TabBar(
- controller: controller,
+ controller: tabController,
tabs: tabs,
indicatorColor: Theme.of(context).colorScheme.primary,
),
@@ -125,7 +131,7 @@ class _CollectPageState extends State<CollectPage>
Widget renderBody(Orientation orientation) {
if (collectController.collectibles.isNotEmpty) {
return TabBarView(
- controller: controller,
+ controller: tabController,
children: contentGrid(collectController.collectibles, orientation),
);
} else {
diff --git a/lib/pages/history/history_page.dart b/lib/pages/history/history_page.dart
index f3103e22..4031d26f 100644
--- a/lib/pages/history/history_page.dart
+++ b/lib/pages/history/history_page.dart
@@ -17,7 +17,6 @@ class HistoryPage extends StatefulWidget {
class _HistoryPageState extends State<HistoryPage>
with SingleTickerProviderStateMixin {
final HistoryController historyController = Modular.get<HistoryController>();
- TabController? controller;
/// show delete button
bool showDelete = false;
diff --git a/lib/pages/info/comments_sheet.dart b/lib/pages/info/comments_sheet.dart
index 3459d936..973f0565 100644
--- a/lib/pages/info/comments_sheet.dart
+++ b/lib/pages/info/comments_sheet.dart
@@ -85,6 +85,7 @@ class _CommentsBottomSheetState extends State<CommentsBottomSheet> {
@override
void dispose() {
+ scrollController.removeListener(scrollListener);
scrollController.dispose();
super.dispose();
}
diff --git a/lib/pages/info/info_page.dart b/lib/pages/info/info_page.dart
index af9778b4..631fe3fd 100644
--- a/lib/pages/info/info_page.dart
+++ b/lib/pages/info/info_page.dart
@@ -57,6 +57,7 @@ class _InfoPageState extends State<InfoPage>
infoController.characterList.clear();
infoController.commentsList.clear();
videoPageController.currentEpisode = 1;
+ tabController.dispose();
super.dispose();
}
diff --git a/lib/pages/popular/popular_page.dart b/lib/pages/popular/popular_page.dart
index a93c7e6e..8ffc5a4a 100644
--- a/lib/pages/popular/popular_page.dart
+++ b/lib/pages/popular/popular_page.dart
@@ -39,17 +39,7 @@ class _PopularPageState extends State<PopularPage>
@override
void initState() {
super.initState();
- scrollController.addListener(() {
- popularController.scrollOffset = scrollController.offset;
- if (scrollController.position.pixels >=
- scrollController.position.maxScrollExtent - 200 &&
- !popularController.isLoadingMore) {
- if (popularController.searchKeyword == '') {
- KazumiLogger().log(Level.info, 'Popular is loading more');
- popularController.queryBangumiListFeed();
- } else {}
- }
- });
+ scrollController.addListener(scrollListener);
if (popularController.bangumiList.isEmpty) {
popularController.queryBangumiListFeed();
}
@@ -67,10 +57,22 @@ class _PopularPageState extends State<PopularPage>
void dispose() {
popularController.isSearching = false;
_focusNode.dispose();
- scrollController.removeListener(() {});
+ scrollController.removeListener(scrollListener);
super.dispose();
}
+ void scrollListener() {
+ popularController.scrollOffset = scrollController.offset;
+ if (scrollController.position.pixels >=
+ scrollController.position.maxScrollExtent - 200 &&
+ !popularController.isLoadingMore) {
+ if (popularController.searchKeyword == '') {
+ KazumiLogger().log(Level.info, 'Popular is loading more');
+ popularController.queryBangumiListFeed();
+ }
+ }
+ }
+
void onBackPressed(BuildContext context) {
if (_lastPressedAt == null ||
DateTime.now().difference(_lastPressedAt!) >
diff --git a/lib/pages/timeline/timeline_page.dart b/lib/pages/timeline/timeline_page.dart
index 2888b896..118a78a2 100644
--- a/lib/pages/timeline/timeline_page.dart
+++ b/lib/pages/timeline/timeline_page.dart
@@ -25,13 +25,13 @@ class _TimelinePageState extends State<TimelinePage>
Modular.get<TimelineController>();
bool showingTimeMachineDialog = false;
late NavigationBarState navigationBarState;
- TabController? controller;
+ TabController? tabController;
@override
void initState() {
super.initState();
int weekday = DateTime.now().weekday - 1;
- controller =
+ tabController =
TabController(vsync: this, length: tabs.length, initialIndex: weekday);
navigationBarState =
Provider.of<NavigationBarState>(context, listen: false);
@@ -40,6 +40,12 @@ class _TimelinePageState extends State<TimelinePage>
}
}
+ @override
+ void dispose() {
+ tabController?.dispose();
+ super.dispose();
+ }
+
void onBackPressed(BuildContext context) {
if (showingTimeMachineDialog) {
KazumiDialog.dismiss();
@@ -97,7 +103,7 @@ class _TimelinePageState extends State<TimelinePage>
needTopOffset: false,
toolbarHeight: 104,
bottom: TabBar(
- controller: controller,
+ controller: tabController,
tabs: tabs,
indicatorColor: Theme.of(context).colorScheme.primary,
),
@@ -174,7 +180,7 @@ class _TimelinePageState extends State<TimelinePage>
Widget renderBody(Orientation orientation) {
if (timelineController.bangumiCalendar.isNotEmpty) {
return TabBarView(
- controller: controller,
+ controller: tabController,
children: contentGrid(timelineController.bangumiCalendar, orientation),
);
} else {
diff --git a/lib/pages/video/video_page.dart b/lib/pages/video/video_page.dart
index 2e8502a1..1ff605fb 100644
--- a/lib/pages/video/video_page.dart
+++ b/lib/pages/video/video_page.dart
@@ -160,6 +160,7 @@ class _VideoPageState extends State<VideoPage>
infoController.episodeInfo.reset();
infoController.episodeCommentsList.clear();
Utils.unlockScreenRotation();
+ tabController.dispose();
super.dispose();
}