@@ -118,23 +118,7 @@ class WebView extends StatelessWidget {
118
118
id: 2 ,
119
119
title: locale.lookup,
120
120
action: () async {
121
- try {
122
- final word = await dict.db! .getOffset (selectedText);
123
- final content = await dict.readWord (word);
124
-
125
- if (context.mounted) {
126
- context.push ("/word" ,
127
- extra: {"content" : content, "word" : word.key});
128
- }
129
- } catch (e) {
130
- final snackBar = SnackBar (
131
- content: Text (locale.notFound),
132
- duration: const Duration (seconds: 1 ),
133
- );
134
- if (context.mounted) {
135
- ScaffoldMessenger .of (context).showSnackBar (snackBar);
136
- }
137
- }
121
+ context.push ("/word" , extra: {"word" : selectedText});
138
122
}),
139
123
ContextMenuItem (
140
124
id: 3 ,
@@ -188,41 +172,57 @@ document.body.style.fontFamily = 'Custom Font';
188
172
}
189
173
190
174
class WebviewDisplay extends StatelessWidget {
191
- final String content;
192
175
final String word;
193
- final bool description;
194
176
195
- const WebviewDisplay (
196
- {super .key,
197
- required this .content,
198
- required this .word,
199
- required this .description});
177
+ const WebviewDisplay ({super .key, required this .word});
200
178
201
179
@override
202
180
Widget build (BuildContext context) {
203
- Widget ? floatingActionButton;
204
- late String html;
205
- if (description) {
206
- html = HtmlUnescape ().convert (content);
207
- } else {
208
- html = content;
209
- floatingActionButton = Button (word: word);
210
- }
181
+ final content = dict.readWord (word);
182
+
183
+ return Scaffold (
184
+ appBar: AppBar (leading: BackButton (
185
+ onPressed: () {
186
+ if (context.canPop ()) {
187
+ context.pop ();
188
+ } else {
189
+ // When opened from context menu
190
+ SystemChannels .platform.invokeMethod ('SystemNavigator.pop' );
191
+ }
192
+ },
193
+ )),
194
+ floatingActionButton: Button (word: word),
195
+ body: FutureBuilder (
196
+ future: content,
197
+ builder: (context, snapshot) {
198
+ if (snapshot.hasData) {
199
+ return WebView (content: snapshot.data! );
200
+ } else if (snapshot.hasError) {
201
+ return Center (
202
+ child: Text (AppLocalizations .of (context)! .notFound,
203
+ style: Theme .of (context).textTheme.titleLarge));
204
+ } else {
205
+ return const Center (child: CircularProgressIndicator ());
206
+ }
207
+ }));
208
+ }
209
+ }
210
+
211
+ class WebviewDisplayDescription extends StatelessWidget {
212
+ const WebviewDisplayDescription ({super .key});
213
+
214
+ @override
215
+ Widget build (BuildContext context) {
216
+ String html = dict.reader! .header["Description" ]! ;
217
+ html = HtmlUnescape ().convert (html);
211
218
212
219
return Scaffold (
213
- appBar: AppBar (leading: BackButton (
214
- onPressed: () {
215
- if (context.canPop ()) {
220
+ appBar: AppBar (leading: BackButton (
221
+ onPressed: () {
216
222
context.pop ();
217
- } else {
218
- // When opened from context menu
219
- SystemChannels .platform.invokeMethod ('SystemNavigator.pop' );
220
- }
221
- },
222
- )),
223
- floatingActionButton: floatingActionButton,
224
- body: WebView (content: html),
225
- );
223
+ },
224
+ )),
225
+ body: WebView (content: html));
226
226
}
227
227
}
228
228
0 commit comments