Skip to content

Commit b9c0332

Browse files
Feature/flutter example (#2)
* doc * flutter example
1 parent fc93c92 commit b9c0332

137 files changed

Lines changed: 4992 additions & 28 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vscode/tasks.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,43 @@
6161
"focus": false,
6262
"clear": true
6363
}
64+
},
65+
{
66+
"label": "[rich_i18n] Run Example",
67+
"type": "shell",
68+
"command": "dart",
69+
"args": [
70+
"run",
71+
"example/main.dart"
72+
],
73+
"options": {
74+
"cwd": "${workspaceFolder}/rich_i18n"
75+
},
76+
"problemMatcher": [],
77+
"presentation": {
78+
"reveal": "always",
79+
"panel": "shared",
80+
"focus": false,
81+
"clear": true
82+
}
83+
},
84+
{
85+
"label": "[flutter_example] Run Flutter Example",
86+
"type": "shell",
87+
"command": "flutter",
88+
"args": [
89+
"run"
90+
],
91+
"options": {
92+
"cwd": "${workspaceFolder}/rich_i18n/flutter_example"
93+
},
94+
"problemMatcher": [],
95+
"presentation": {
96+
"reveal": "always",
97+
"panel": "shared",
98+
"focus": false,
99+
"clear": true
100+
}
64101
}
65102
]
66103
}
260 KB
Loading

rich_i18n/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
## [0.1.1](https://github.com/MattiaPispisa/rich_i18n/tree/rich_i18n-v0.1.1/rich_i18n)
2+
3+
[compare to previous release](https://github.com/MattiaPispisa/rich_i18n/compare/rich_i18n-v0.1.0...rich_i18n-v0.1.1)
4+
5+
6+
**Date:** 2026-01-10
7+
8+
### Added
9+
- Flutter example app in the `flutter_example` directory.
10+
11+
### Changed
12+
13+
- chore: documentation
14+
115
## [0.1.0](https://github.com/MattiaPispisa/rich_i18n/tree/rich_i18n-v0.1.0/rich_i18n)
216
**Date:** 2026-01-10
317

rich_i18n/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,21 @@ final items = tryGetRichTextSync('Invalid <b>XML');
8282
- Consecutive text segments with the same style are automatically merged
8383
- Empty tags are ignored (no unnecessary items created)
8484

85+
## Flutter Example
86+
87+
A complete Flutter example app is available in the `flutter_example` directory,
88+
demonstrating how to convert the parsed `RichTextItem` objects into Flutter's
89+
`TextSpan` widgets for rendering rich text in Flutter applications.
90+
91+
The example includes an interactive editor where you can:
92+
- Edit XML source with rich text tags
93+
- See the rendered preview in real-time
94+
- Test various formatting options (bold, underline, colors, links, etc.)
95+
96+
<img width="500" alt="rich_text_flutter_example" src="https://raw.githubusercontent.com/MattiaPispisa/rich_i18n/main/assets/rich_text_flutter_example.png">
97+
98+
To run the Flutter example:
99+
85100
## Why not Flutter?
86101

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

rich_i18n/example/main.dart

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// ignore_for_file: avoid_print just for example purposes
22

3+
import 'dart:async';
4+
35
import 'package:rich_i18n/rich_i18n.dart';
46

57
void main() async {
@@ -9,7 +11,7 @@ void main() async {
911
print('');
1012

1113
// Example 1: Basic text parsing with bold tag
12-
_sectionPrintLayout(
14+
await _sectionPrintLayout(
1315
title: 'Example 1: Basic bold text',
1416
body: () {
1517
final basicItems = tryGetRichTextSync('Hello <b>World</b>!');
@@ -24,7 +26,7 @@ void main() async {
2426
);
2527

2628
// Example 2: Nested tags
27-
_sectionPrintLayout(
29+
await _sectionPrintLayout(
2830
title: 'Example 2: Nested tags (bold and underline)',
2931
body: () {
3032
final nestedItems = tryGetRichTextSync(
@@ -41,7 +43,7 @@ void main() async {
4143
);
4244

4345
// Example 3: Multiple text styles
44-
_sectionPrintLayout(
46+
await _sectionPrintLayout(
4547
title: 'Example 3: Multiple text styles',
4648
body: () {
4749
final stylesItems = tryGetRichTextSync(
@@ -64,7 +66,7 @@ void main() async {
6466
);
6567

6668
// Example 4: Span with attributes (color, font size, etc.)
67-
_sectionPrintLayout(
69+
await _sectionPrintLayout(
6870
title: 'Example 4: Span with attributes',
6971
body: () {
7072
final spanItems = tryGetRichTextSync(
@@ -82,7 +84,7 @@ void main() async {
8284
},
8385
);
8486
// Example 5: Background color and font family
85-
_sectionPrintLayout(
87+
await _sectionPrintLayout(
8688
title: 'Example 5: Background color and font family',
8789
body: () {
8890
final styledItems = tryGetRichTextSync(
@@ -99,7 +101,7 @@ void main() async {
99101
},
100102
);
101103
// Example 6: Links
102-
_sectionPrintLayout(
104+
await _sectionPrintLayout(
103105
title: 'Example 6: Hyperlinks',
104106
body: () {
105107
final linkItems = tryGetRichTextSync(
@@ -115,7 +117,7 @@ void main() async {
115117
);
116118

117119
// Example 7: Complex nested structure
118-
_sectionPrintLayout(
120+
await _sectionPrintLayout(
119121
title: 'Example 7: Complex nested structure',
120122
body: () {
121123
final complexItems = tryGetRichTextSync(
@@ -136,7 +138,7 @@ void main() async {
136138
);
137139

138140
// Example 8: Error handling with tryGetRichTextSync (returns null)
139-
_sectionPrintLayout(
141+
await _sectionPrintLayout(
140142
title: 'Example 8: Error handling (invalid XML)',
141143
body: () {
142144
final invalidItems = tryGetRichTextSync('Invalid <b>unclosed tag');
@@ -147,7 +149,7 @@ void main() async {
147149
);
148150

149151
// Example 9: Verbose mode with error reporting
150-
await _sectionPrintLayoutAsync(
152+
await _sectionPrintLayout(
151153
title: 'Example 9: Verbose mode (with descriptors)',
152154
body: () async {
153155
try {
@@ -178,7 +180,7 @@ void main() async {
178180
);
179181

180182
// Example 10: Empty tags are ignored (merged)
181-
_sectionPrintLayout(
183+
await _sectionPrintLayout(
182184
title: 'Example 10: Consecutive same-style segments are merged',
183185
body: () {
184186
final mergedItems = tryGetRichTextSync('<b>hello</b><b> world</b>');
@@ -197,22 +199,12 @@ void main() async {
197199
print('=' * 60);
198200
}
199201

200-
void _sectionPrintLayout({
201-
required String title,
202-
void Function()? body,
203-
}) {
204-
print(title);
205-
print('-' * 60);
206-
body?.call();
207-
print('');
208-
}
209-
210-
Future<void> _sectionPrintLayoutAsync({
202+
Future<void> _sectionPrintLayout({
211203
required String title,
212-
required Future<void> Function() body,
204+
FutureOr<void> Function()? body,
213205
}) async {
214206
print(title);
215207
print('-' * 60);
216-
await body();
208+
await body?.call();
217209
print('');
218210
}

rich_i18n/flutter_example/.fvmrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"flutter": "stable"
3+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.build/
9+
.buildlog/
10+
.history
11+
.svn/
12+
.swiftpm/
13+
migrate_working_dir/
14+
15+
# IntelliJ related
16+
*.iml
17+
*.ipr
18+
*.iws
19+
.idea/
20+
21+
# The .vscode folder contains launch configuration and tasks you configure in
22+
# VS Code which you may wish to be included in version control, so this line
23+
# is commented out by default.
24+
#.vscode/
25+
26+
# Flutter/Dart/Pub related
27+
**/doc/api/
28+
**/ios/Flutter/.last_build_id
29+
.dart_tool/
30+
.flutter-plugins-dependencies
31+
.pub-cache/
32+
.pub/
33+
/build/
34+
/coverage/
35+
36+
# Symbolication related
37+
app.*.symbols
38+
39+
# Obfuscation related
40+
app.*.map.json
41+
42+
# Android Studio will place build artifacts here
43+
/android/app/debug
44+
/android/app/profile
45+
/android/app/release
46+
47+
# FVM Version Cache
48+
.fvm/
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: "f6ff1529fd6d8af5f706051d9251ac9231c83407"
8+
channel: "stable"
9+
10+
project_type: app
11+
12+
# Tracks metadata for the flutter migrate command
13+
migration:
14+
platforms:
15+
- platform: root
16+
create_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407
17+
base_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407
18+
- platform: android
19+
create_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407
20+
base_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407
21+
- platform: ios
22+
create_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407
23+
base_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407
24+
- platform: linux
25+
create_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407
26+
base_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407
27+
- platform: macos
28+
create_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407
29+
base_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407
30+
- platform: web
31+
create_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407
32+
base_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407
33+
- platform: windows
34+
create_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407
35+
base_revision: f6ff1529fd6d8af5f706051d9251ac9231c83407
36+
37+
# User provided section
38+
39+
# List of Local paths (relative to this file) that should be
40+
# ignored by the migrate tool.
41+
#
42+
# Files that are not part of the templates will be ignored by default.
43+
unmanaged_files:
44+
- 'lib/main.dart'
45+
- 'ios/Runner.xcodeproj/project.pbxproj'
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# flutter_example
2+
3+
A new Flutter project.
4+
5+
## Getting Started
6+
7+
This project is a starting point for a Flutter application.
8+
9+
A few resources to get you started if this is your first Flutter project:
10+
11+
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
12+
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
13+
14+
For help getting started with Flutter development, view the
15+
[online documentation](https://docs.flutter.dev/), which offers tutorials,
16+
samples, guidance on mobile development, and a full API reference.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include: package:flutter_lints/flutter.yaml
2+
3+
linter:
4+
rules:

0 commit comments

Comments
 (0)