tag_styled_text package
Straightforward xml tag based (rich) styling on Text
widgets
Add this library to your pubspec.yaml file by either running
flutter pub add tag_styled_text
or by manually inserting
#(...)
dependencies:
tag_styled_text: ^<desired version here>
#(...)
By itself, the package doesn't offer any default tags, you will have to add them yourself like so:
for a full showcase of functionalities take a look at the
example
app
// in your material app definition
MaterialApp(
// (...)
builder: (context, child) {
// inserting the application default tag styles here
return DefaultTagStyles(
tags: {
'bold': const TextSpanTag(
style: TextStyle(fontWeight: FontWeight.bold),
),
'italic': const TextSpanTag(
style: TextStyle(fontStyle: FontStyle.italic),
),
},
child: child!,
);
},
// (...)
);
Then instead of using normally Text
widgets, we would instead use:
// simple tag usage
TagStyledText('Some <bold>bold text</bold>!');
// nested tag usage
TagStyledText('Some <bold>bold and <italic>italic text</italic></bold>!');
// if you need to add special tags only on specific instaces
TagStyledText(
'Some text with <bold><special>a special text</special></bold>',
// tags here will be merged with any existing DefaultTagStyles on the widget tree
// allowing both <special> and <bold> to be used without re-declaration.
// if you add a tag here that is already present on the DefaultTagStyles,
// it will take priority.
tags: {
'special': const TextSpanTag(style: TextStyle(color: Colors.pink)),
},
);