Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danreynolds/rich_text_composer
https://github.com/danreynolds/rich_text_composer
Last synced: 2 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/danreynolds/rich_text_composer
- Owner: danReynolds
- License: mit
- Created: 2023-09-18T03:17:45.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-09-18T03:19:36.000Z (about 1 year ago)
- Last Synced: 2023-09-18T03:36:04.325Z (about 1 year ago)
- Language: Dart
- Size: 0 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Rich text composer
Sometimes `RichText` composing is easier with pattern matching. `RichTextComposer` turns composition like this:
```dart
RichText(
text: TextSpan(
children: [
TextSpan("The forecast for today is ", style: TextStyle(color: Colors.black)),
TextSpan(weatherType, style: TextStyle(fontWeight: FontWeight.bold)),
TextSpan(" with a high of ", style: TextStyle(color: Colors.black)),
TextSpan(temperatureMax, style: TextStyle(color: Colors.red)),
]
)
)
```into this:
```dart
RichTextComposer(
text: "The forecast for today is @weatherType with a high of @high",
richTextBuilders: [
RichTextPatternBuilder(
pattern: RegExp('@weatherType'),
builder: (
text, {
required endIndex,
required matchIndex,
required startIndex,
}) {
return TextSpan(text: weatherType, style: TextStyle(fontWeight: FontWeight.bold));
},
),
RichTextPatternBuilder(
pattern: RegExp('@high'),
builder: (
text, {
required endIndex,
required matchIndex,
required startIndex,
}) {
return TextSpan(text: high, style: TextStyle(color: Colors.red));
},
),
],
plainTextBuilder: (text) => TextSpan(
text: text,
style: TextStyle(color: Colors.black)
),
)
```