logout method
Implementation
Future<void> logout() async {
String? accessToken = SpUtil.getString(BytedeskConstants.accessToken);
if (accessToken!.isNotEmpty) {
Map<String, String> headers = {"Content-Type": "application/json"};
//
var body = json.encode({"client": client});
final initUrl = BytedeskUtils.getHostUri(
'/api/user/logout', {'access_token': accessToken});
final initResponse =
await httpClient.post(initUrl, headers: headers, body: body);
//解决json解析中的乱码问题
Utf8Decoder utf8decoder = const Utf8Decoder(); // fix 中文乱码
//将string类型数据 转换为json类型的数据
final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes));
debugPrint("logout:$responseJson");
BytedeskUtils.clearUserCache();
}
}