I have a list of text span like this
var spans = [
TextSpan(text: content, style: style),
TextSpan(text: content, style: style)
//and 100 more
]
I am loading this inside SingleChildScrollView like this.
SingleChildScrollView(
controller: scrollController,
child: Text.rich(
TextSpan(children: spans),
),
)
Now My question is how can I shift focus between the TextSpan
list?. Say I want to load TextSpan
at position 10 from spans
list at top of screen without manually scrolling.
You could add a
WidgetSpan
next to each of yourTextSpan
, so you can assign it akey
property which would be aGlobalKey
so you can access itsBuildContext
to call the methodScrollable.ensureVisible()
.Here's a code sample inspired by an answer to a similar question:
Try the sample on DartPad