✨ Shuffle mode
This commit is contained in:
parent
02c28533db
commit
fa3ba0e188
@ -9,7 +9,7 @@ class PostProvider extends GetConnect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Response> listRecommendations(int page,
|
Future<Response> listRecommendations(int page,
|
||||||
{int? realm, String? tag, category}) async {
|
{int? realm, String? tag, category, String? channel}) async {
|
||||||
final queries = [
|
final queries = [
|
||||||
'take=${10}',
|
'take=${10}',
|
||||||
'offset=$page',
|
'offset=$page',
|
||||||
@ -17,7 +17,11 @@ class PostProvider extends GetConnect {
|
|||||||
if (category != null) 'category=$category',
|
if (category != null) 'category=$category',
|
||||||
if (realm != null) 'realmId=$realm',
|
if (realm != null) 'realmId=$realm',
|
||||||
];
|
];
|
||||||
final resp = await get('/recommendations?${queries.join('&')}');
|
final resp = await get(
|
||||||
|
channel == null
|
||||||
|
? '/recommendations?${queries.join('&')}'
|
||||||
|
: '/recommendations/$channel?${queries.join('&')}',
|
||||||
|
);
|
||||||
if (resp.statusCode != 200) {
|
if (resp.statusCode != 200) {
|
||||||
throw Exception(resp.body);
|
throw Exception(resp.body);
|
||||||
}
|
}
|
||||||
|
@ -20,16 +20,24 @@ class HomeScreen extends StatefulWidget {
|
|||||||
State<HomeScreen> createState() => _HomeScreenState();
|
State<HomeScreen> createState() => _HomeScreenState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _HomeScreenState extends State<HomeScreen> {
|
class _HomeScreenState extends State<HomeScreen>
|
||||||
|
with SingleTickerProviderStateMixin {
|
||||||
final PagingController<int, Post> _pagingController =
|
final PagingController<int, Post> _pagingController =
|
||||||
PagingController(firstPageKey: 0);
|
PagingController(firstPageKey: 0);
|
||||||
|
|
||||||
|
late final TabController _tabController;
|
||||||
|
|
||||||
|
int mode = 0;
|
||||||
|
|
||||||
getPosts(int pageKey) async {
|
getPosts(int pageKey) async {
|
||||||
final PostProvider provider = Get.find();
|
final PostProvider provider = Get.find();
|
||||||
|
|
||||||
Response resp;
|
Response resp;
|
||||||
try {
|
try {
|
||||||
resp = await provider.listRecommendations(pageKey);
|
resp = await provider.listRecommendations(
|
||||||
|
pageKey,
|
||||||
|
channel: mode == 0 ? null : 'shuffle',
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_pagingController.error = e;
|
_pagingController.error = e;
|
||||||
return;
|
return;
|
||||||
@ -48,6 +56,16 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_pagingController.addPageRequestListener(getPosts);
|
_pagingController.addPageRequestListener(getPosts);
|
||||||
|
_tabController = TabController(length: 2, vsync: this);
|
||||||
|
_tabController.addListener(() {
|
||||||
|
switch (_tabController.index) {
|
||||||
|
case 0:
|
||||||
|
case 1:
|
||||||
|
if (mode == _tabController.index) break;
|
||||||
|
mode = _tabController.index;
|
||||||
|
_pagingController.refresh();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -68,8 +86,10 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
),
|
),
|
||||||
body: RefreshIndicator(
|
body: RefreshIndicator(
|
||||||
onRefresh: () => Future.sync(() => _pagingController.refresh()),
|
onRefresh: () => Future.sync(() => _pagingController.refresh()),
|
||||||
child: CustomScrollView(
|
child: NestedScrollView(
|
||||||
slivers: [
|
headerSliverBuilder:
|
||||||
|
(BuildContext context, bool innerBoxIsScrolled) {
|
||||||
|
return [
|
||||||
SliverAppBar(
|
SliverAppBar(
|
||||||
title: AppBarTitle('home'.tr),
|
title: AppBarTitle('home'.tr),
|
||||||
centerTitle: false,
|
centerTitle: false,
|
||||||
@ -83,10 +103,28 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
width: SolianTheme.isLargeScreen(context) ? 8 : 16,
|
width: SolianTheme.isLargeScreen(context) ? 8 : 16,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
bottom: TabBar(
|
||||||
FeedListWidget(controller: _pagingController),
|
controller: _tabController,
|
||||||
|
tabs: [
|
||||||
|
Tab(text: 'postListNews'.tr),
|
||||||
|
Tab(text: 'postListShuffle'.tr),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
)
|
||||||
|
];
|
||||||
|
},
|
||||||
|
body: TabBarView(
|
||||||
|
controller: _tabController,
|
||||||
|
children: [
|
||||||
|
CustomScrollView(slivers: [
|
||||||
|
FeedListWidget(controller: _pagingController),
|
||||||
|
]),
|
||||||
|
CustomScrollView(slivers: [
|
||||||
|
FeedListWidget(controller: _pagingController),
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -83,6 +83,8 @@ const messagesEnglish = {
|
|||||||
'notifyAllRead': 'Mark all as read',
|
'notifyAllRead': 'Mark all as read',
|
||||||
'notifyEmpty': 'All notifications read',
|
'notifyEmpty': 'All notifications read',
|
||||||
'notifyEmptyCaption': 'It seems like nothing happened recently',
|
'notifyEmptyCaption': 'It seems like nothing happened recently',
|
||||||
|
'postListNews': 'News',
|
||||||
|
'postListShuffle': 'Random',
|
||||||
'postEditor': 'Create new post',
|
'postEditor': 'Create new post',
|
||||||
'articleEditor': 'Create new article',
|
'articleEditor': 'Create new article',
|
||||||
'articleDetail': 'Article details',
|
'articleDetail': 'Article details',
|
||||||
|
@ -81,6 +81,8 @@ const simplifiedChineseMessages = {
|
|||||||
'articleEditor': '撰写文章',
|
'articleEditor': '撰写文章',
|
||||||
'articleDetail': '文章详情',
|
'articleDetail': '文章详情',
|
||||||
'draftBoxOpen': '打开草稿箱',
|
'draftBoxOpen': '打开草稿箱',
|
||||||
|
'postListNews': '新鲜事',
|
||||||
|
'postListShuffle': '打乱看',
|
||||||
'postNew': '创建新帖子',
|
'postNew': '创建新帖子',
|
||||||
'postNewInRealmHint': '在领域 @realm 里发表新帖子',
|
'postNewInRealmHint': '在领域 @realm 里发表新帖子',
|
||||||
'postAction': '发表',
|
'postAction': '发表',
|
||||||
|
Loading…
Reference in New Issue
Block a user