11import 'package:example/main.client.dart' ;
2+ import 'package:example/main.dart' ;
23import 'package:jaspr/dom.dart' ;
34import 'package:jaspr/jaspr.dart' ;
45import 'package:romanize/romanize.dart' ;
@@ -12,8 +13,8 @@ class Home extends StatefulComponent {
1213}
1314
1415class _HomeState extends State <Home > {
15- String _text = '안녕하세요, 만나서 반갑습니다.' ;
16- late List <RomanizedText > _romanized = TextRomanizer . analyze (_text);
16+ String _text = multiLanguagesText ;
17+ late Future < List <RomanizedText >> _romanized = service. convert (_text);
1718
1819 void _syncScroll (web.Event event, String otherId) {
1920 final source = event.target as web.HTMLElement ;
@@ -70,10 +71,10 @@ class _HomeState extends State<Home> {
7071 final sectionStyle = Styles (
7172 display: Display .flex,
7273 height: Unit .percent (70 ),
73- minWidth: Unit .pixels (300 ),
74+ minWidth: Unit .pixels (200 ),
7475 flexDirection: FlexDirection .column,
7576 gap: Gap .all (Unit .pixels (12 )),
76- flex: Flex (grow: 1 , shrink: 0 , basis: Unit .pixels (400 )),
77+ flex: Flex (grow: 1 , shrink: 0 , basis: Unit .pixels (200 )),
7778 );
7879
7980 final labelStyle = Styles (
@@ -100,9 +101,10 @@ class _HomeState extends State<Home> {
100101 },
101102 placeholder: 'Type your text here...' ,
102103 onInput: (text) async {
103- _text = text;
104- _romanized = await service.convert (text);
105- if (mounted) setState (() {});
104+ setState (() {
105+ _text = text;
106+ _romanized = service.convert (text);
107+ });
106108 },
107109 required : true ,
108110 spellCheck: SpellCheck .isFalse,
@@ -114,30 +116,39 @@ class _HomeState extends State<Home> {
114116 ]),
115117 div (styles: sectionStyle, [
116118 h3 (styles: labelStyle, [.text ('Output' )]),
117- div (
118- id: 'output-area' ,
119- events: {
120- 'scroll' : (e) => _syncScroll (e, 'input-area' ),
121- },
122- styles: textareaStyle.combine (
123- Styles (
124- overflow: Overflow .auto,
125- whiteSpace: WhiteSpace .preWrap,
126- backgroundColor: Color ('#f9fafb' ),
127- raw: {
128- 'word-break' : 'break-word' ,
119+ FutureBuilder <List <RomanizedText >>(
120+ future: _romanized,
121+ builder: (context, snapshot) {
122+ return div (
123+ id: 'output-area' ,
124+ events: {
125+ 'scroll' : (e) => _syncScroll (e, 'input-area' ),
129126 },
130- ),
131- ),
132- _romanized.map ((item) {
133- return span (
134- styles: Styles (
135- color: _getColorForLanguage (item.language),
136- fontWeight: FontWeight .w500,
127+ styles: textareaStyle.combine (
128+ Styles (
129+ overflow: Overflow .auto,
130+ whiteSpace: WhiteSpace .preWrap,
131+ backgroundColor: Color ('#f9fafb' ),
132+ raw: {
133+ 'word-break' : 'break-word' ,
134+ },
135+ ),
137136 ),
138- [.text (item.romanizedText)],
137+ snapshot.hasData
138+ ? snapshot.data! .map ((item) {
139+ return span (
140+ styles: Styles (
141+ color: _getColorForLanguage (item.language),
142+ fontWeight: FontWeight .w500,
143+ ),
144+ [.text (item.romanizedText)],
145+ );
146+ }).toList ()
147+ : [
148+ .text ('Loading resources...' ),
149+ ],
139150 );
140- }). toList () ,
151+ },
141152 ),
142153 ]),
143154 ],
0 commit comments