Is there a way to detect which word in the TextSpan
was touched by the user?
This paragraph is here to get round the stack overflow robot that is insisting that I write more stuff :)
TextSpan is an immutable span of text. It has style property to give style to the text. It is also having children property to add more text to this widget and give style to the children.
Flutter – Center Align Text in Text Widget To center align the text in a Text widget, provide textAlign property with value TextAlign. center .
You can improve by yourself
import 'package:flutter/gestures.dart'; ... new RichText( text: new TextSpan(text: 'Non touchable. ', children: [ new TextSpan( text: 'Tap here.', recognizer: new TapGestureRecognizer()..onTap = () => print('Tap Here onTap'), ) ]), );
Screenshot:
Use recognizer
property of TextSpan
which allows almost all types of event.
RichText( text: TextSpan( children: [ TextSpan( text: 'Single tap', style: TextStyle(color: Colors.red[300]), recognizer: TapGestureRecognizer()..onTap = () { // Single tapped. }, ), TextSpan( text: ' Double tap', style: TextStyle(color: Colors.green[300]), recognizer: DoubleTapGestureRecognizer()..onDoubleTap = () { // Double tapped. } ), TextSpan( text: ' Long press', style: TextStyle(color: Colors.blue[300]), recognizer: LongPressGestureRecognizer()..onLongPress = () { // Long Pressed. }, ), ], ), )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With