flutter - I/flutter:FormatException:输入意外结束(在字符 1 处)
问题描述
- 当我尝试向服务器发布 OrderRate 和评论时遇到错误,我收到以下错误。
I/flutter (28194): 错误是: FormatException: Unexpected end of input (at character 1)
- 这也是导致问题的代码:
Future<void> addRateOrder(String comment, int rate, String orderId) async{
Map<String, dynamic> rateOrderData = Map();
rateOrderData['Comment'] = comment;
rateOrderData['Rate'] = rate.toString();
try{
String url = Urls.buildRateOrder(orderId);
final response = await retry(
()=>http.post(url,
body: rateOrderData)
.timeout(Duration(seconds: 5)),
retryIf: (e)=> e is SocketException || e is TimeoutException
);
final responseData =json.decode(response.body);
print(responseData);
}catch(error){
print('error is: $error');
throw error;
}
}
解决方案
有时它是由于在您的代码中两次向同一个 Api 发送相同的请求而发生的