11// ignore_for_file: avoid_print just for example purposes
22
3+ import 'dart:async' ;
4+
35import 'package:rich_i18n/rich_i18n.dart' ;
46
57void 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}
0 commit comments