diff --git a/assets/locales/en_us.json b/assets/locales/en_us.json index cf4ea74..7714c16 100644 --- a/assets/locales/en_us.json +++ b/assets/locales/en_us.json @@ -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" } diff --git a/assets/locales/zh_cn.json b/assets/locales/zh_cn.json index 006c774..623ca40 100644 --- a/assets/locales/zh_cn.json +++ b/assets/locales/zh_cn.json @@ -484,5 +484,7 @@ "fileSavedAt": "文件保存于 @path", "showIp": "显示 IP 地址", "shotOn": "由 @device 拍摄", - "unread": "未读" + "unread": "未读", + "searchTook": "耗时 @time", + "searchResult": "匹配到 @count 条结果" } diff --git a/lib/screens/posts/post_search.dart b/lib/screens/posts/post_search.dart index 92feef9..e5c3907 100644 --- a/lib/screens/posts/post_search.dart +++ b/lib/screens/posts/post_search.dart @@ -20,6 +20,9 @@ class PostSearchScreen extends StatefulWidget { } class _PostSearchScreenState extends State { + int? _totalCount; + Duration? _lastTook; + final TextEditingController _probeController = TextEditingController(); final PagingController _pagingController = PagingController(firstPageKey: 0); @@ -43,18 +46,20 @@ class _PostSearchScreenState extends State { _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 { _pagingController.appendLastPage(parsed); } + stopwatch.stop(); + + _totalCount = result.count; + _lastTook = stopwatch.elapsed; + setState(() => _isBusy = false); } @@ -90,6 +100,9 @@ class _PostSearchScreenState extends State { 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 { ), ), 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()),