From e844870c34d216cf3b32a09832781da6db8b7624 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sun, 29 Oct 2023 00:38:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=90=9C=E7=B4=A2=E5=BB=BA=E8=AE=AE?= =?UTF-8?q?=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/http/search.dart | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/http/search.dart b/lib/http/search.dart index 7b21c2cd..b94ace2c 100644 --- a/lib/http/search.dart +++ b/lib/http/search.dart @@ -39,16 +39,25 @@ class SearchHttp { static Future searchSuggest({required term}) async { var res = await Request().get(Api.serachSuggest, data: {'term': term, 'main_ver': 'v1', 'highlight': term}); - if (res.data['code'] == 0) { - if (res.data['result'] is Map) { - res.data['result']['term'] = term; + if (res.data is String) { + Map resultMap = json.decode(res.data); + if (resultMap['code'] == 0) { + if (resultMap['result'] is Map) { + resultMap['result']['term'] = term; + } + return { + 'status': true, + 'data': resultMap['result'] is Map + ? SearchSuggestModel.fromJson(resultMap['result']) + : [], + }; + } else { + return { + 'status': false, + 'data': [], + 'msg': '请求错误 🙅', + }; } - return { - 'status': true, - 'data': res.data['result'] is Map - ? SearchSuggestModel.fromJson(res.data['result']) - : [], - }; } else { return { 'status': false,