This is great to skip lots of boilerplate. To further simplify things, I created this helper class to centralize styles and add some padding:
var appTheme = ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(seedColor: const Color(0x006AAE3F)),
);
[...]
class Txt extends StatelessWidget {
const Txt(
this.text, {
super.key,
this.padding = 2,
this.extraTags = const {},
});
final String text;
final double padding;
final Map extraTags;
static var appStyleTags = {
'h1': StyledTextTag(
style: TextStyle(
height: 2, fontSize: 50, color: appTheme.colorScheme.primary)),
'h2': StyledTextTag(
// textTheme sizes not working for some reason...
style: appTheme.textTheme.headlineMedium!.copyWith(
color: appTheme.colorScheme.primary,
)),
'b': StyledTextTag(style: const TextStyle(fontWeight: FontWeight.bold)),
'i': StyledTextTag(style: const TextStyle(fontStyle: FontStyle.italic)),
};
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.all(padding),
child: StyledText(text: text, tags: {...appStyleTags, ...extraTags}));
}
}
so now I can do Txt('<i>Be <b>Bold</b> and Italic') or Txt('<spacey>This<br>is<br><i>spacey!', padding: 10, extraTags: {'spacey': StyledTextTag(style: TextStyle(height: 10))}). Perhaps someone would find it useful too. Would be nice to have something akin in the library itself!
This is great to skip lots of boilerplate. To further simplify things, I created this helper class to centralize styles and add some padding:
so now I can do
Txt('<i>Be <b>Bold</b> and Italic')
orTxt('<spacey>This<br>is<br><i>spacey!', padding: 10, extraTags: {'spacey': StyledTextTag(style: TextStyle(height: 10))})
. Perhaps someone would find it useful too. Would be nice to have something akin in the library itself!