I am building where I want to highlight text that starts with "@" and "#" and also make them clickable in flutter but cant seem to find any link or package that does it. The only able to get is the hashtag flutter package hashtagtext
CodePudding user response:
have you tried using Elevated Button, OutlinedButton, TextButton, or GestureDetector?
OutlinedButton(onPressed: () {}, child: Text('@Test'),),
ElevatedButton(onPressed: () {}, child: Text('@Test'),),
TextButton(onPressed: () {}, child: Text('@Test'),),
GestureDetector(onTap: () {}, child: Text('@Test'),),
CodePudding user response:
you can use Text.rich:
Text.rich(
TextSpan(
text: 'Bla bla bla ',
style: const TextStyle(
color: Colors.black,
fontSize: 30,
fontWeight: FontWeight.bold,
),
children: <InlineSpan>[
WidgetSpan(
child: TextButton(
onPressed: () { print('@blablabla'); },
child: Text('@blablabla'),
),
),
const TextSpan(
text: 'bla bla bla.',
),
],
),
),