rich_i18n 0.1.2
rich_i18n: ^0.1.2 copied to clipboard
A Dart library for parsing rich text with XML tags into structured items.
rich_i18n #
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 #
RichTextItemcaches itshashCodeat 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.)
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