Skip to content

Instantly share code, notes, and snippets.

@BarryDaBee
Created April 13, 2023 00:19
Show Gist options
  • Save BarryDaBee/822cccad99801331a5b1438d36f1197f to your computer and use it in GitHub Desktop.
Save BarryDaBee/822cccad99801331a5b1438d36f1197f to your computer and use it in GitHub Desktop.
Sample showing how to create Text with clickable words
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
class ClickableTextView extends StatelessWidget {
final String text;
const ClickableTextView({Key? key, required this.text}) : super(key: key);
@override
Widget build(BuildContext context) {
return RichText(
text: TextSpan(
style: const TextStyle(
color: Colors.black,
fontSize: 24,
),
children: text
.split(' ')
.map(
(word) => TextSpan(
text: '$word ',
recognizer: LongPressGestureRecognizer()
..onLongPress = () {
showDialog(
context: context,
builder: (context) {
return Dialog(
backgroundColor: Colors.white,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
word.replaceAll(RegExp('[^a-zA-Z]'), ''),
style:
Theme.of(context).textTheme.headlineLarge,
)
],
),
);
},
);
},
),
)
.toList(),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment