Summary on search post

This commit is contained in:
LittleSheep 2024-10-16 22:49:34 +08:00
parent 88587c10da
commit b3267f0026
3 changed files with 58 additions and 5 deletions

View File

@ -488,5 +488,7 @@
"fileSavedAt": "File saved at @path",
"showIp": "Show IP Address",
"shotOn": "Shot on @device",
"unread": "Unread"
"unread": "Unread",
"searchTook": "Took @time",
"searchResult": "@count Matches"
}

View File

@ -484,5 +484,7 @@
"fileSavedAt": "文件保存于 @path",
"showIp": "显示 IP 地址",
"shotOn": "由 @device 拍摄",
"unread": "未读"
"unread": "未读",
"searchTook": "耗时 @time",
"searchResult": "匹配到 @count 条结果"
}

View File

@ -20,6 +20,9 @@ class PostSearchScreen extends StatefulWidget {
}
class _PostSearchScreenState extends State<PostSearchScreen> {
int? _totalCount;
Duration? _lastTook;
final TextEditingController _probeController = TextEditingController();
final PagingController<int, Post> _pagingController =
PagingController(firstPageKey: 0);
@ -43,18 +46,20 @@ class _PostSearchScreenState extends State<PostSearchScreen> {
_pagingController.nextPageKey = 0;
}
final PostProvider provider = Get.find();
final PostProvider posts = Get.find();
Stopwatch stopwatch = new Stopwatch()..start();
Response resp;
try {
if (_probeController.text.isEmpty) {
resp = await provider.listPost(
resp = await posts.listPost(
pageKey,
tag: widget.tag,
category: widget.category,
);
} else {
resp = await provider.searchPost(
resp = await posts.searchPost(
_probeController.text,
pageKey,
tag: widget.tag,
@ -74,6 +79,11 @@ class _PostSearchScreenState extends State<PostSearchScreen> {
_pagingController.appendLastPage(parsed);
}
stopwatch.stop();
_totalCount = result.count;
_lastTook = stopwatch.elapsed;
setState(() => _isBusy = false);
}
@ -90,6 +100,9 @@ class _PostSearchScreenState extends State<PostSearchScreen> {
super.dispose();
}
Color get _unFocusColor =>
Theme.of(context).colorScheme.onSurface.withOpacity(0.75);
@override
Widget build(BuildContext context) {
return Scaffold(
@ -136,6 +149,42 @@ class _PostSearchScreenState extends State<PostSearchScreen> {
),
),
LoadingIndicator(isActive: _isBusy),
if (_totalCount != null || _lastTook != null)
Container(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 4),
child: Row(
children: [
Icon(
Icons.summarize_outlined,
size: 16,
color: _unFocusColor,
),
const Gap(4),
if (_totalCount != null)
Text(
'searchResult'.trParams({
'count': _totalCount!.toString(),
}),
style: TextStyle(
fontSize: 13,
color: _unFocusColor,
),
),
const Gap(4),
if (_lastTook != null)
Text(
'searchTook'.trParams({
'time':
'${(_lastTook!.inMilliseconds / 1000).toStringAsFixed(3)}s',
}),
style: TextStyle(
fontSize: 13,
color: _unFocusColor,
),
),
],
),
),
Expanded(
child: RefreshIndicator(
onRefresh: () => Future.sync(() => _pagingController.refresh()),