rich_i18n 0.1.1 copy "rich_i18n: ^0.1.1" to clipboard
rich_i18n: ^0.1.1 copied to clipboard

A Dart library for parsing rich text with XML tags into structured items.

rich_i18n #

package badge pub points pub likes codecov ci badge license, pub publisher,

A Dart library for parsing rich text with XML tags into structured items.

Installation #

dependencies:
  rich_i18n: ^0.1.0

Usage #

Basic Example #

import 'package:rich_i18n/rich_i18n.dart';

final items = tryGetRichTextSync('Hello <b>World</b>!');
// Result:
// [
//   RichTextItem(text: 'Hello '),
//   RichTextItem(text: 'World', fontWeight: 700),
//   RichTextItem(text: '!'),
// ]

Nested Tags #

final items = tryGetRichTextSync('Hello <b>bold and <u>underline</u></b>!');
// Result:
// [
//   RichTextItem(text: 'Hello '),
//   RichTextItem(text: 'bold and ', fontWeight: 700),
//   RichTextItem(text: 'underline', fontWeight: 700, textDecoration: 'underline'),
//   RichTextItem(text: '!'),
// ]

All Supported Tags #

See the full list of supported tags in the tryGetRichTextSync API documentation.

Span Attributes #

final items = tryGetRichTextSync('''
  <span 
    color="#FF0000" 
    background-color="yellow"
    >
    Styled text
  </span>
''');

See the full list of supported attributes in the tryGetRichTextSync API documentation.

Error Handling #

If the input contains invalid XML, the original text is returned as a single RichTextItem:

final items = tryGetRichTextSync('Invalid <b>XML');
// Result: [RichTextItem(text: 'Invalid <b>XML')]

Performance #

  • RichTextItem caches its hashCode at construction time for efficient use in collections
  • Consecutive text segments with the same style are automatically merged
  • Empty tags are ignored (no unnecessary items created)

Flutter Example #

A complete Flutter example app is available in the flutter_example directory, demonstrating how to convert the parsed RichTextItem objects into Flutter's TextSpan widgets for rendering rich text in Flutter applications.

The example includes an interactive editor where you can:

  • Edit XML source with rich text tags
  • See the rendered preview in real-time
  • Test various formatting options (bold, underline, colors, links, etc.)
rich_text_flutter_example

Why not Flutter? #

This library is intentionally framework-agnostic and has no Flutter dependency:

  • No version constraints: Your app won't have conflicts with Flutter SDK versions
  • No custom widgets to maintain: You don't need to import and maintain a third-party widget in your codebase
  • Maximum flexibility: Convert to TextSpan, HTML, or any other format you need
  • Pure Dart: Can be used in CLI tools, servers, or any Dart project
1
likes
150
points
127
downloads

Publisher

verified publishermattiapispisa.it

Weekly Downloads

A Dart library for parsing rich text with XML tags into structured items.

Homepage
Repository (GitHub)
View/report issues

Topics

#i18n #rich-text #xml #styling

Documentation

API reference

License

MIT (license)

Dependencies

xml

More

Packages that depend on rich_i18n