💄 Optimize the explore page app bar behavior
This commit is contained in:
parent
382e3c4a4c
commit
af7cc8dab0
@ -1,3 +1,4 @@
|
|||||||
|
import 'dart:async';
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
@ -33,9 +34,18 @@ class PostListController extends GetxController {
|
|||||||
pagingController.addPageRequestListener(_onPagingControllerRequest);
|
pagingController.addPageRequestListener(_onPagingControllerRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Completer<void>? _pagingLoadCompleter;
|
||||||
|
|
||||||
Future<void> _onPagingControllerRequest(int pageKey) async {
|
Future<void> _onPagingControllerRequest(int pageKey) async {
|
||||||
try {
|
try {
|
||||||
|
if (_pagingLoadCompleter != null) {
|
||||||
|
await _pagingLoadCompleter!.future;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_pagingLoadCompleter = Completer();
|
||||||
final result = await loadMore();
|
final result = await loadMore();
|
||||||
|
_pagingLoadCompleter!.complete();
|
||||||
|
_pagingLoadCompleter = null;
|
||||||
|
|
||||||
if (result != null && hasMore.value) {
|
if (result != null && hasMore.value) {
|
||||||
pagingController.appendPage(result, nextPageKey.value);
|
pagingController.appendPage(result, nextPageKey.value);
|
||||||
@ -99,9 +109,6 @@ class PostListController extends GetxController {
|
|||||||
hasMore.value = false;
|
hasMore.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final idx = <dynamic>{};
|
|
||||||
postList.retainWhere((x) => idx.add(x.id));
|
|
||||||
|
|
||||||
if (postList.isNotEmpty) {
|
if (postList.isNotEmpty) {
|
||||||
var lastId = postList.map((x) => x.id).reduce(max);
|
var lastId = postList.map((x) => x.id).reduce(max);
|
||||||
Get.find<LastReadProvider>().feedLastReadAt = lastId;
|
Get.find<LastReadProvider>().feedLastReadAt = lastId;
|
||||||
@ -121,6 +128,7 @@ class PostListController extends GetxController {
|
|||||||
resp = await posts.listPost(
|
resp = await posts.listPost(
|
||||||
pageKey,
|
pageKey,
|
||||||
author: author,
|
author: author,
|
||||||
|
take: 10,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
switch (mode.value) {
|
switch (mode.value) {
|
||||||
@ -129,6 +137,7 @@ class PostListController extends GetxController {
|
|||||||
pageKey,
|
pageKey,
|
||||||
channel: 'shuffle',
|
channel: 'shuffle',
|
||||||
realm: realm,
|
realm: realm,
|
||||||
|
take: 10,
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
@ -136,12 +145,14 @@ class PostListController extends GetxController {
|
|||||||
pageKey,
|
pageKey,
|
||||||
channel: 'friends',
|
channel: 'friends',
|
||||||
realm: realm,
|
realm: realm,
|
||||||
|
take: 10,
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
resp = await posts.listRecommendations(
|
resp = await posts.listRecommendations(
|
||||||
pageKey,
|
pageKey,
|
||||||
realm: realm,
|
realm: realm,
|
||||||
|
take: 10,
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -28,11 +28,11 @@ class PostProvider extends GetConnect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Response> listRecommendations(int page,
|
Future<Response> listRecommendations(int page,
|
||||||
{String? realm, String? channel}) async {
|
{String? realm, String? channel, int take = 10}) async {
|
||||||
GetConnect client;
|
GetConnect client;
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
final queries = [
|
final queries = [
|
||||||
'take=${10}',
|
'take=$take',
|
||||||
'offset=$page',
|
'offset=$page',
|
||||||
if (realm != null) 'realm=$realm',
|
if (realm != null) 'realm=$realm',
|
||||||
];
|
];
|
||||||
@ -71,9 +71,9 @@ class PostProvider extends GetConnect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Response> listPost(int page,
|
Future<Response> listPost(int page,
|
||||||
{String? realm, String? author, tag, category}) async {
|
{String? realm, String? author, tag, category, int take = 10}) async {
|
||||||
final queries = [
|
final queries = [
|
||||||
'take=${10}',
|
'take=$take',
|
||||||
'offset=$page',
|
'offset=$page',
|
||||||
if (tag != null) 'tag=$tag',
|
if (tag != null) 'tag=$tag',
|
||||||
if (category != null) 'category=$category',
|
if (category != null) 'category=$category',
|
||||||
|
@ -75,10 +75,12 @@ class _DashboardScreenState extends State<DashboardScreen> {
|
|||||||
final src = Get.find<MessagesFetchingProvider>();
|
final src = Get.find<MessagesFetchingProvider>();
|
||||||
final out = await src.getWhatsNewEvents(_lastRead.messagesLastReadAt!);
|
final out = await src.getWhatsNewEvents(_lastRead.messagesLastReadAt!);
|
||||||
if (out == null) return;
|
if (out == null) return;
|
||||||
setState(() {
|
if (mounted) {
|
||||||
_currentMessages = out.$1;
|
setState(() {
|
||||||
_currentMessagesCount = out.$2;
|
_currentMessages = out.$1;
|
||||||
});
|
_currentMessagesCount = out.$2;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _signingDaily = true;
|
bool _signingDaily = true;
|
||||||
|
@ -80,62 +80,85 @@ class _ExploreScreenState extends State<ExploreScreen>
|
|||||||
body: NestedScrollView(
|
body: NestedScrollView(
|
||||||
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
|
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
|
||||||
return [
|
return [
|
||||||
SliverAppBar(
|
SliverLayoutBuilder(
|
||||||
flexibleSpace: SizedBox(
|
builder: (context, constraints) {
|
||||||
height: 48,
|
final scrollOffset = constraints.scrollOffset;
|
||||||
child: const Row(
|
final colorChangeOffset = 120;
|
||||||
children: [
|
|
||||||
RealmSwitcher(),
|
final scrollProgress =
|
||||||
|
(scrollOffset / colorChangeOffset).clamp(0.0, 1.0);
|
||||||
|
final backgroundColor = Color.lerp(
|
||||||
|
Theme.of(context)
|
||||||
|
.colorScheme
|
||||||
|
.surfaceContainerLow
|
||||||
|
.withOpacity(0),
|
||||||
|
Theme.of(context)
|
||||||
|
.colorScheme
|
||||||
|
.surfaceContainerLow
|
||||||
|
.withOpacity(0.9),
|
||||||
|
scrollProgress,
|
||||||
|
);
|
||||||
|
|
||||||
|
return SliverAppBar(
|
||||||
|
backgroundColor: backgroundColor,
|
||||||
|
flexibleSpace: SizedBox(
|
||||||
|
height: 48,
|
||||||
|
child: const Row(
|
||||||
|
children: [
|
||||||
|
RealmSwitcher(),
|
||||||
|
],
|
||||||
|
).paddingSymmetric(horizontal: 8),
|
||||||
|
).paddingOnly(top: MediaQuery.of(context).padding.top),
|
||||||
|
snap: true,
|
||||||
|
floating: true,
|
||||||
|
toolbarHeight: AppTheme.toolbarHeight(context),
|
||||||
|
leading: AppBarLeadingButton.adaptive(context),
|
||||||
|
actions: [
|
||||||
|
const BackgroundStateWidget(),
|
||||||
|
const NotificationButton(),
|
||||||
|
SizedBox(
|
||||||
|
width: AppTheme.isLargeScreen(context) ? 8 : 16,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
).paddingSymmetric(horizontal: 8),
|
bottom: TabBar(
|
||||||
).paddingOnly(top: MediaQuery.of(context).padding.top),
|
controller: _tabController,
|
||||||
floating: true,
|
dividerHeight: 0.3,
|
||||||
toolbarHeight: AppTheme.toolbarHeight(context),
|
tabAlignment: TabAlignment.fill,
|
||||||
leading: AppBarLeadingButton.adaptive(context),
|
tabs: [
|
||||||
actions: [
|
Tab(
|
||||||
const BackgroundStateWidget(),
|
child: Row(
|
||||||
const NotificationButton(),
|
mainAxisSize: MainAxisSize.min,
|
||||||
SizedBox(
|
children: [
|
||||||
width: AppTheme.isLargeScreen(context) ? 8 : 16,
|
const Icon(Icons.feed, size: 20),
|
||||||
),
|
const Gap(8),
|
||||||
],
|
Text('postListNews'.tr),
|
||||||
bottom: TabBar(
|
],
|
||||||
controller: _tabController,
|
),
|
||||||
dividerHeight: 0.3,
|
),
|
||||||
tabAlignment: TabAlignment.fill,
|
Tab(
|
||||||
tabs: [
|
child: Row(
|
||||||
Tab(
|
mainAxisSize: MainAxisSize.min,
|
||||||
child: Row(
|
children: [
|
||||||
mainAxisSize: MainAxisSize.min,
|
const Icon(Icons.people, size: 20),
|
||||||
children: [
|
const Gap(8),
|
||||||
const Icon(Icons.feed, size: 20),
|
Text('postListFriends'.tr),
|
||||||
const Gap(8),
|
],
|
||||||
Text('postListNews'.tr),
|
),
|
||||||
],
|
),
|
||||||
),
|
Tab(
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.shuffle_on_outlined, size: 20),
|
||||||
|
const Gap(8),
|
||||||
|
Text('postListShuffle'.tr),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
Tab(
|
);
|
||||||
child: Row(
|
},
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
const Icon(Icons.people, size: 20),
|
|
||||||
const Gap(8),
|
|
||||||
Text('postListFriends'.tr),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Tab(
|
|
||||||
child: Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
const Icon(Icons.shuffle_on_outlined, size: 20),
|
|
||||||
const Gap(8),
|
|
||||||
Text('postListShuffle'.tr),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
|
@ -546,7 +546,6 @@ class _PostEditorTextField extends StatelessWidget {
|
|||||||
final Function onUpdate;
|
final Function onUpdate;
|
||||||
|
|
||||||
const _PostEditorTextField({
|
const _PostEditorTextField({
|
||||||
super.key,
|
|
||||||
required this.focusNode,
|
required this.focusNode,
|
||||||
required this.controller,
|
required this.controller,
|
||||||
required this.onUpdate,
|
required this.onUpdate,
|
||||||
|
Loading…
Reference in New Issue
Block a user