About this widget
Displays the highlighted attributes of your search results. TheHighlightedString
objects simplify highlighting the right words in a search response that match your query.
Examples
Consider a movies index. Each movie record consists of two fields:title
and year
.
Algolia’s response to the query “red” could look like:
JSON
data class
that looks something like the following:
Dart
Movie
instance from the Hit
object.
Extract highlighted strings from search hit JSON
Complete theMovie
class with the highlightedTitle
property of the HighlightedString
type.
Update the fromJson
method so that it parses the HighlightedString
from the hit using the getHighlightedString
method.
Dart
HighlightedString
can be created directly from the raw tagged string.
Dart
Using highlighted strings in Flutter
TheHighlightedString
provides a toInlineSpans()
method which produces a list of InlineSpan
instances.
The highlightedTextStyle
parameter of this method defines the style of the highlighted part of the text.
These instances, in turn, can be used as a parameter in Flutter’s RichText widget as follows:
Dart