Flutter – How to create a Clickable Text

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,
      ),
    );
  }
}
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x