💄 Optimize the explore page app bar behavior

This commit is contained in:
LittleSheep 2024-10-10 23:36:07 +08:00
parent 382e3c4a4c
commit af7cc8dab0
5 changed files with 101 additions and 66 deletions

View File

@ -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;
} }

View File

@ -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',

View File

@ -75,11 +75,13 @@ 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;
if (mounted) {
setState(() { setState(() {
_currentMessages = out.$1; _currentMessages = out.$1;
_currentMessagesCount = out.$2; _currentMessagesCount = out.$2;
}); });
} }
}
bool _signingDaily = true; bool _signingDaily = true;
DailySignRecord? _signRecord; DailySignRecord? _signRecord;

View File

@ -80,7 +80,27 @@ class _ExploreScreenState extends State<ExploreScreen>
body: NestedScrollView( body: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) { headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return [ return [
SliverAppBar( SliverLayoutBuilder(
builder: (context, constraints) {
final scrollOffset = constraints.scrollOffset;
final colorChangeOffset = 120;
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( flexibleSpace: SizedBox(
height: 48, height: 48,
child: const Row( child: const Row(
@ -89,6 +109,7 @@ class _ExploreScreenState extends State<ExploreScreen>
], ],
).paddingSymmetric(horizontal: 8), ).paddingSymmetric(horizontal: 8),
).paddingOnly(top: MediaQuery.of(context).padding.top), ).paddingOnly(top: MediaQuery.of(context).padding.top),
snap: true,
floating: true, floating: true,
toolbarHeight: AppTheme.toolbarHeight(context), toolbarHeight: AppTheme.toolbarHeight(context),
leading: AppBarLeadingButton.adaptive(context), leading: AppBarLeadingButton.adaptive(context),
@ -136,6 +157,8 @@ class _ExploreScreenState extends State<ExploreScreen>
), ),
], ],
), ),
);
},
) )
]; ];
}, },

View File

@ -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,