Add a failsafe for extraData searches

This commit is contained in:
Oystein Kristoffer Tveit 2022-05-01 23:34:11 +02:00
parent eaa5510942
commit 76061a42f1
1 changed files with 5 additions and 3 deletions

View File

@ -32,6 +32,7 @@ class SearchResultCard extends StatefulWidget {
class _SearchResultCardState extends State<SearchResultCard> {
PhrasePageScrapeResultData? extraData;
bool? extraDataSearchFailed;
Future<PhrasePageScrapeResult?> _scrape(JishoResult result) =>
(!(result.japanese[0].word == null && result.japanese[0].reading == null))
@ -133,18 +134,19 @@ class _SearchResultCardState extends State<SearchResultCard> {
if (extensiveSearchEnabled && extraData == null) {
final data = await _scrape(widget.result);
setState(() {
extraData = (data != null && data.found) ? data.data : null;
extraDataSearchFailed = !(data?.found ?? false);
extraData = !extraDataSearchFailed! ? data!.data : null;
});
}
},
title: _header,
children: [
if (extensiveSearchEnabled && extraData == null)
if (extensiveSearchEnabled && extraDataSearchFailed == null)
const Padding(
padding: EdgeInsets.symmetric(vertical: 10),
child: Center(child: CircularProgressIndicator()),
)
else if (extraData != null)
else if (!extraDataSearchFailed!)
_body(extendedData: extraData)
else
_body()