From 7c53da02c84da356415af261f222b75a67f0e28b Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Thu, 29 Aug 2024 10:42:03 +0800 Subject: [PATCH] fix: null safety --- lib/http/video.dart | 50 +++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/lib/http/video.dart b/lib/http/video.dart index 5b0ac158..7fab7992 100644 --- a/lib/http/video.dart +++ b/lib/http/video.dart @@ -352,20 +352,18 @@ class VideoHttp { // (取消)点赞 static Future likeVideo({required String bvid, required bool type}) async { - var res = await Request().post( - Api.likeVideo, - queryParameters: { - 'aid': IdUtils.bv2av(bvid), - 'like': type ? 0 : 1, - 'access_key': GStorage.localCache - .get(LocalCacheKey.accessKey, defaultValue: {})['value'], - } - // queryParameters: { - // 'bvid': bvid, - // 'like': type ? 1 : 2, - // 'csrf': await Request.getCsrf(), - // }, - ); + var res = await Request().post(Api.likeVideo, queryParameters: { + 'aid': IdUtils.bv2av(bvid), + 'like': type ? 0 : 1, + 'access_key': GStorage.localCache + .get(LocalCacheKey.accessKey, defaultValue: {})['value'], + } + // queryParameters: { + // 'bvid': bvid, + // 'like': type ? 1 : 2, + // 'csrf': await Request.getCsrf(), + // }, + ); if (res.data['code'] == 0) { return {'status': true, 'data': res.data['data']}; } else { @@ -594,9 +592,17 @@ class VideoHttp { 'csrf': await Request.getCsrf(), }); if (res.data['code'] == 0) { - return {'status': true, 'msg': res.data['result']['toast']}; + return { + 'status': true, + 'msg': + res.data['result'] == null ? 'failed' : res.data['result']['toast'] + }; } else { - return {'status': false, 'msg': res.data['result']['toast']}; + return { + 'status': false, + 'msg': + res.data['result'] == null ? 'failed' : res.data['result']['toast'] + }; } } @@ -607,9 +613,17 @@ class VideoHttp { 'csrf': await Request.getCsrf(), }); if (res.data['code'] == 0) { - return {'status': true, 'msg': res.data['result']['toast']}; + return { + 'status': true, + 'msg': + res.data['result'] == null ? 'failed' : res.data['result']['toast'] + }; } else { - return {'status': false, 'msg': res.data['result']['toast']}; + return { + 'status': false, + 'msg': + res.data['result'] == null ? 'failed' : res.data['result']['toast'] + }; } }