createInteractiveText function
- required BuildContext context,
- required String text,
- required VoidCallback onTap,
- required TextStyle style,
- bool isClickable = true,
Creates an interactive text widget with consistent styling and behavior.
This function generates a widget that allows for selectable and optionally
clickable text. When isClickable
is true, the text will respond to user
taps by executing the provided onTap
callback. The cursor will also change
to indicate interactivity.
Implementation
Widget createInteractiveText({
required BuildContext context,
required String text,
required VoidCallback onTap,
required TextStyle style,
bool isClickable = true,
}) {
return MouseRegion(
cursor: isClickable ? SystemMouseCursors.click : SystemMouseCursors.text,
child: SelectableText.rich(
TextSpan(
text: text,
style: style,
recognizer:
isClickable ? (TapGestureRecognizer()..onTap = onTap) : null,
),
),
);
}