✨ Summary on search post
This commit is contained in:
parent
88587c10da
commit
b3267f0026
@ -488,5 +488,7 @@
|
|||||||
"fileSavedAt": "File saved at @path",
|
"fileSavedAt": "File saved at @path",
|
||||||
"showIp": "Show IP Address",
|
"showIp": "Show IP Address",
|
||||||
"shotOn": "Shot on @device",
|
"shotOn": "Shot on @device",
|
||||||
"unread": "Unread"
|
"unread": "Unread",
|
||||||
|
"searchTook": "Took @time",
|
||||||
|
"searchResult": "@count Matches"
|
||||||
}
|
}
|
||||||
|
@ -484,5 +484,7 @@
|
|||||||
"fileSavedAt": "文件保存于 @path",
|
"fileSavedAt": "文件保存于 @path",
|
||||||
"showIp": "显示 IP 地址",
|
"showIp": "显示 IP 地址",
|
||||||
"shotOn": "由 @device 拍摄",
|
"shotOn": "由 @device 拍摄",
|
||||||
"unread": "未读"
|
"unread": "未读",
|
||||||
|
"searchTook": "耗时 @time",
|
||||||
|
"searchResult": "匹配到 @count 条结果"
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,9 @@ class PostSearchScreen extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _PostSearchScreenState extends State<PostSearchScreen> {
|
class _PostSearchScreenState extends State<PostSearchScreen> {
|
||||||
|
int? _totalCount;
|
||||||
|
Duration? _lastTook;
|
||||||
|
|
||||||
final TextEditingController _probeController = TextEditingController();
|
final TextEditingController _probeController = TextEditingController();
|
||||||
final PagingController<int, Post> _pagingController =
|
final PagingController<int, Post> _pagingController =
|
||||||
PagingController(firstPageKey: 0);
|
PagingController(firstPageKey: 0);
|
||||||
@ -43,18 +46,20 @@ class _PostSearchScreenState extends State<PostSearchScreen> {
|
|||||||
_pagingController.nextPageKey = 0;
|
_pagingController.nextPageKey = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
final PostProvider provider = Get.find();
|
final PostProvider posts = Get.find();
|
||||||
|
|
||||||
|
Stopwatch stopwatch = new Stopwatch()..start();
|
||||||
|
|
||||||
Response resp;
|
Response resp;
|
||||||
try {
|
try {
|
||||||
if (_probeController.text.isEmpty) {
|
if (_probeController.text.isEmpty) {
|
||||||
resp = await provider.listPost(
|
resp = await posts.listPost(
|
||||||
pageKey,
|
pageKey,
|
||||||
tag: widget.tag,
|
tag: widget.tag,
|
||||||
category: widget.category,
|
category: widget.category,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
resp = await provider.searchPost(
|
resp = await posts.searchPost(
|
||||||
_probeController.text,
|
_probeController.text,
|
||||||
pageKey,
|
pageKey,
|
||||||
tag: widget.tag,
|
tag: widget.tag,
|
||||||
@ -74,6 +79,11 @@ class _PostSearchScreenState extends State<PostSearchScreen> {
|
|||||||
_pagingController.appendLastPage(parsed);
|
_pagingController.appendLastPage(parsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stopwatch.stop();
|
||||||
|
|
||||||
|
_totalCount = result.count;
|
||||||
|
_lastTook = stopwatch.elapsed;
|
||||||
|
|
||||||
setState(() => _isBusy = false);
|
setState(() => _isBusy = false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,6 +100,9 @@ class _PostSearchScreenState extends State<PostSearchScreen> {
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Color get _unFocusColor =>
|
||||||
|
Theme.of(context).colorScheme.onSurface.withOpacity(0.75);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@ -136,6 +149,42 @@ class _PostSearchScreenState extends State<PostSearchScreen> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
LoadingIndicator(isActive: _isBusy),
|
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(
|
Expanded(
|
||||||
child: RefreshIndicator(
|
child: RefreshIndicator(
|
||||||
onRefresh: () => Future.sync(() => _pagingController.refresh()),
|
onRefresh: () => Future.sync(() => _pagingController.refresh()),
|
||||||
|
Loading…
Reference in New Issue
Block a user