Closed fingerart closed 3 weeks ago
It is very necessary to get the theme through context to adapt the colors of different themes.
// <font color="theme_color_name|hex_number" size="number" face="font_family" weight="number" />
'font': StyledTextCustomTag(parse: (context, baseStyle, attributes) {
final rawColor = attributes['color'];
Color? color = context.appColors.byName(rawColor) ?? parseColor(rawColor);
return TextStyle(color: color);
})
You can use the parent widget context:
@override
Widget build(BuildContext context) {
// ^-----
return Scaffold(
body: Center(
child: StyledText(
text: 'Hello, <font color="accent">World</font>!',
tags: {
'font': StyledTextCustomTag(
parse: (baseStyle, attributes) {
final rawColor = attributes['color'];
Color? color = context.appColors.byName(rawColor) ?? parseColor(rawColor);
return TextStyle(color: color);
},
),
},
),
),
);
}
Is it really necessary? What problem will it solve, can you give a code example?