As you know, in Flutter Text is “unclickable”. In this post, we are going to create a “clickable” Text by wrapping the Text under GestureDetector.
import 'package:flutter/material.dart';
class ClickableText extends StatelessWidget {
final String text;
final TextStyle? style;
final Function onPressed;
const ClickableText(
{Key? key, required this.text, this.style, required this.onPressed})
: super(key: key);
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
onPressed.call();
},
child: Text(
text,
style: style,
),
);
}
}