tag_styled_text 0.0.1 copy "tag_styled_text: ^0.0.1" to clipboard
tag_styled_text: ^0.0.1 copied to clipboard

Straightforward xml tag based (rich) styling on Text widgets

xml_styled_text package #

build codecov

Straightforward xml tag based (rich) styling on Text widgets

Getting started #

Add this library to your pubspec.yaml file by either running

flutter pub add xml_styled_text

or by manually inserting

#(...)
dependencies:
  xml_styled_text: ^<desired version here>
#(...)

Usage #

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)),
  },
);
1
likes
130
points
43
downloads

Publisher

unverified uploader

Weekly Downloads

Straightforward xml tag based (rich) styling on Text widgets

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

collection, flutter, xml

More

Packages that depend on tag_styled_text