I am trying to create a Rich text widget that has clickable links.
import 'package:flutter/cupertino.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; class InlineTapableElements extends StatefulWidget { @override _DemoComponentState createState() => _DemoComponentState(); } class _DemoComponentState extends State<InlineTapableElements> { TapGestureRecognizer _recognizer = TapGestureRecognizer() ..onTap = () { print('tapped on textspan'); }; @override Widget build(BuildContext context) { return SelectableText.rich( TextSpan( children: [ TextSpan( text: 'Some text', recognizer: _recognizer) ].toList())); } @override void dispose() { _recognizer.dispose(); super.dispose(); } }
Whenever i am using SelectableText.rich to build, the tap recognizers are not getting recognized. But if i am using the norma Text.rich method, then everything seems working fine. Is there a solution by which i can make the text selectable and listen to the click events directly from the TextSpan or InlineSpan elements.