at main 1.3 kB view raw
1import 'package:flutter/material.dart'; 2 3import '../utils/facet_utils.dart'; 4 5class FacetedText extends StatelessWidget { 6 final String text; 7 final List<Map<String, dynamic>>? facets; 8 final TextStyle? style; 9 final TextStyle? linkStyle; 10 final void Function(String did)? onMentionTap; 11 final void Function(String url)? onLinkTap; 12 final void Function(String tag)? onTagTap; 13 14 const FacetedText({ 15 super.key, 16 required this.text, 17 this.facets, 18 this.style, 19 this.linkStyle, 20 this.onMentionTap, 21 this.onLinkTap, 22 this.onTagTap, 23 }); 24 25 @override 26 Widget build(BuildContext context) { 27 final theme = Theme.of(context); 28 final defaultStyle = style ?? theme.textTheme.bodyMedium; 29 final defaultLinkStyle = 30 linkStyle ?? 31 defaultStyle?.copyWith( 32 color: theme.colorScheme.primary, 33 fontWeight: FontWeight.w600, 34 decoration: TextDecoration.underline, 35 ); 36 37 if (facets == null || facets!.isEmpty) { 38 return Text(text, style: defaultStyle); 39 } 40 41 final spans = FacetUtils.processFacets( 42 text: text, 43 facets: facets, 44 defaultStyle: defaultStyle, 45 linkStyle: defaultLinkStyle, 46 onMentionTap: onMentionTap, 47 onLinkTap: onLinkTap, 48 onTagTap: onTagTap, 49 ); 50 51 return RichText(text: TextSpan(children: spans)); 52 } 53}