Record the last state of the favorite pane.

This commit is contained in:
2025-02-05 20:40:14 +08:00
parent 24155746f2
commit 23404b86f6
2 changed files with 43 additions and 18 deletions

View File

@@ -1388,34 +1388,60 @@ class _FavoritePanel extends StatefulWidget {
State<_FavoritePanel> createState() => _FavoritePanelState(); State<_FavoritePanel> createState() => _FavoritePanelState();
} }
class _FavoritePanelState extends State<_FavoritePanel> { class _FavoritePanelState extends State<_FavoritePanel>
with SingleTickerProviderStateMixin {
late ComicSource comicSource; late ComicSource comicSource;
late TabController tabController;
late bool hasNetwork;
@override @override
void initState() { void initState() {
comicSource = widget.type.comicSource!; comicSource = widget.type.comicSource!;
localFolders = LocalFavoritesManager().folderNames; localFolders = LocalFavoritesManager().folderNames;
added = LocalFavoritesManager().find(widget.cid, widget.type); added = LocalFavoritesManager().find(widget.cid, widget.type);
hasNetwork = comicSource.favoriteData != null && comicSource.isLogged;
var initIndex = 0;
if (appdata.implicitData['favoritePanelIndex'] is int) {
initIndex = appdata.implicitData['favoritePanelIndex'];
}
initIndex = initIndex.clamp(0, hasNetwork ? 1 : 0);
tabController = TabController(
initialIndex: initIndex,
length: hasNetwork ? 2 : 1,
vsync: this,
);
super.initState(); super.initState();
} }
@override
void dispose() {
var currentIndex = tabController.index;
appdata.implicitData['favoritePanelIndex'] = currentIndex;
appdata.writeImplicitData();
tabController.dispose();
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var hasNetwork = comicSource.favoriteData != null && comicSource.isLogged;
return Scaffold( return Scaffold(
appBar: Appbar( appBar: Appbar(
title: Text("Favorite".tl), title: Text("Favorite".tl),
), ),
body: DefaultTabController( body: Column(
length: hasNetwork ? 2 : 1,
child: Column(
children: [ children: [
TabBar(tabs: [ TabBar(
controller: tabController,
tabs: [
Tab(text: "Local".tl), Tab(text: "Local".tl),
if (hasNetwork) Tab(text: "Network".tl), if (hasNetwork) Tab(text: "Network".tl),
]), ],
),
Expanded( Expanded(
child: TabBarView( child: TabBarView(
controller: tabController,
children: [ children: [
buildLocal(), buildLocal(),
if (hasNetwork) buildNetwork(), if (hasNetwork) buildNetwork(),
@@ -1424,7 +1450,6 @@ class _FavoritePanelState extends State<_FavoritePanel> {
), ),
], ],
), ),
),
); );
} }

View File

@@ -42,7 +42,7 @@ class _CommentsPageState extends State<CommentsPage> {
_error = res.errorMessage; _error = res.errorMessage;
_loading = false; _loading = false;
}); });
} else { } else if (mounted) {
setState(() { setState(() {
_comments = res.data; _comments = res.data;
_loading = false; _loading = false;