Skip to content

Instantly share code, notes, and snippets.

@huynguyennovem
Created November 15, 2022 15:34
Show Gist options
  • Save huynguyennovem/af55e71b1d55523fb51256cb57b582df to your computer and use it in GitHub Desktop.
Save huynguyennovem/af55e71b1d55523fb51256cb57b582df to your computer and use it in GitHub Desktop.
A common class ClickableText using in Flutter
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
class ClickableText extends StatelessWidget {
final String? text;
final TextStyle? textStyle;
final Function? onTapAction;
const ClickableText({
Key? key,
this.text,
this.textStyle,
this.onTapAction,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return RichText(
text: TextSpan(
text: text,
style: textStyle ??
TextStyle(
decoration: TextDecoration.underline,
color: Colors.lightBlueAccent.shade200,
fontSize: 16.0,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.normal,
),
recognizer: TapGestureRecognizer()..onTap = () => onTapAction?.call(),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment