From 76061a42f1869956f3a2fdf79763b4fc762e2129 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Sun, 1 May 2022 23:34:11 +0200 Subject: [PATCH] Add a failsafe for extraData searches --- .../search/search_results_body/search_card.dart | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/components/search/search_results_body/search_card.dart b/lib/components/search/search_results_body/search_card.dart index fe5968b..63a9bbe 100644 --- a/lib/components/search/search_results_body/search_card.dart +++ b/lib/components/search/search_results_body/search_card.dart @@ -32,6 +32,7 @@ class SearchResultCard extends StatefulWidget { class _SearchResultCardState extends State { PhrasePageScrapeResultData? extraData; + bool? extraDataSearchFailed; Future _scrape(JishoResult result) => (!(result.japanese[0].word == null && result.japanese[0].reading == null)) @@ -133,18 +134,19 @@ class _SearchResultCardState extends State { 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()