Skip to content

Commit

Permalink
fix: post list error
Browse files Browse the repository at this point in the history
  • Loading branch information
gvenusleo committed Jan 16, 2023
1 parent acd7834 commit 21048d2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 70 deletions.
28 changes: 4 additions & 24 deletions lib/routes/feed/feed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,10 @@ class FeedPageState extends State<FeedPage> {
Map<String, dynamic> readPageInitData = {};

Future<void> getPostList() async {
if (onlyUnread) {
await getUnreadPostList();
} else if (onlyFavorite) {
getFavoritePostList();
} else {
List<Post> temp = await postsByFeedId(widget.feed.id!);
setState(() {
postList = temp;
});
}
List<Post> temp = await postsByFeedId(widget.feed.id!);
setState(() {
postList = temp;
});
}

Future<void> getUnreadPostList() async {
Expand All @@ -57,19 +51,9 @@ class FeedPageState extends State<FeedPage> {
});
}

Future getInitState() async {
bool onlyUnreadTem = await getOnlyUnread();
bool onlyFavoriteTem = await getOnlyFavorite();
setState(() {
onlyUnread = onlyUnreadTem;
onlyFavorite = onlyFavoriteTem;
});
}

@override
void initState() {
super.initState();
getInitState();
getPostList();
}

Expand Down Expand Up @@ -97,8 +81,6 @@ class FeedPageState extends State<FeedPage> {
onlyFavorite = false;
});
}
await setOnlyUnread(onlyUnread);
await setOnlyFavorite(onlyFavorite);
},
icon: onlyUnread
? const Icon(Icons.radio_button_checked)
Expand All @@ -118,8 +100,6 @@ class FeedPageState extends State<FeedPage> {
onlyUnread = false;
});
}
await setOnlyUnread(onlyUnread);
await setOnlyFavorite(onlyFavorite);
},
icon: onlyFavorite
? const Icon(Icons.bookmark)
Expand Down
28 changes: 4 additions & 24 deletions lib/routes/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,10 @@ class HomePageState extends State<HomePage> {
}

Future<void> getPostList() async {
if (onlyUnread) {
await getUnreadPost();
} else if (onlyFavorite) {
await getFavoritePost();
} else {
List<Post> temp = await posts();
setState(() {
postList = temp;
});
}
List<Post> temp = await posts();
setState(() {
postList = temp;
});
}

Future<void> getUnreadPost() async {
Expand Down Expand Up @@ -123,19 +117,9 @@ class HomePageState extends State<HomePage> {
checkPostCount(feedMaxSaveCount);
}

Future getInitState() async {
bool onlyUnreadTem = await getOnlyUnread();
bool onlyFavoriteTem = await getOnlyFavorite();
setState(() {
onlyUnread = onlyUnreadTem;
onlyFavorite = onlyFavoriteTem;
});
}

@override
void initState() {
super.initState();
getInitState();
getFeedList();
getPostList();
getUnreadCount();
Expand Down Expand Up @@ -166,8 +150,6 @@ class HomePageState extends State<HomePage> {
onlyFavorite = false;
});
}
await setOnlyUnread(onlyUnread);
await setOnlyFavorite(onlyFavorite);
},
icon: onlyUnread
? const Icon(Icons.radio_button_checked)
Expand All @@ -187,8 +169,6 @@ class HomePageState extends State<HomePage> {
onlyUnread = false;
});
}
await setOnlyUnread(onlyUnread);
await setOnlyFavorite(onlyFavorite);
},
icon: onlyFavorite
? const Icon(Icons.bookmark)
Expand Down
22 changes: 0 additions & 22 deletions lib/utils/key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,3 @@ Future<Map<String, dynamic>> getAllReadPageInitData() async {
'customCss': prefs.getString('customCss') ?? '',
};
}

// 是否只读模式
Future<bool> getOnlyUnread() async {
final prefs = await SharedPreferences.getInstance();
return prefs.getBool('isOnlyRead') ?? false;
}

Future<void> setOnlyUnread(bool isOnlyRead) async {
final prefs = await SharedPreferences.getInstance();
prefs.setBool('isOnlyRead', isOnlyRead);
}

// 是否收藏模式
Future<bool> getOnlyFavorite() async {
final prefs = await SharedPreferences.getInstance();
return prefs.getBool('isOnlyFavorite') ?? false;
}

Future<void> setOnlyFavorite(bool isOnlyFavorite) async {
final prefs = await SharedPreferences.getInstance();
prefs.setBool('isOnlyFavorite', isOnlyFavorite);
}

0 comments on commit 21048d2

Please sign in to comment.