UI libraries
/
Algolia for Flutter
/
Widgets
Nov 14, 2024
Stats
About this widget
Each search Response
contains various metadata you might display in your search experience.
The following information is available as a part of the Response
:
hitsPerPage
: Number of hits per page.nbHits
: Total number of hits.nbPages
: Total number of pages.page
: Current page.processingTimeMS
: Processing time of the request (in ms).query
: Query text that produced these results.
Examples
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class SearchStats extends StatelessWidget {
const SearchStats(this.responses, {super.key});
final Stream<SearchResponse> responses;
@override
Widget build(BuildContext context) {
return StreamBuilder<SearchResponse>(
stream: responses,
builder: (context, snapshot) => Text(stats(snapshot.data)));
}
String stats(SearchResponse? response) {
if (response == null) return '';
final buffer = StringBuffer();
if (!response.exhaustiveNbHits) buffer.write("~");
buffer.write("${response.nbHits} hits ");
buffer.write("in ${response.processingTimeMS} ms");
return buffer.toString();
}
}
Did you find this page helpful?