飘动多个itemCount?

时间:2020-03-23 05:35:03

标签: flutter

我在1个屏幕中有3个JSON请求,代码工作正常,但有时2秒却显示错误信息:

发生了异常。
NoSuchMethodError(NoSuchMethodError:方法'[]'在null上调用。 接收者:null
尝试调用:[](0))

,然后再次恢复正常,仅2秒就闪烁了一个红色屏幕错误。

String url1 = "https://api-1.php"; 
    var response1 = await http
        .get(Uri.encodeFull(url1), headers: {"Accept": "application/json"});

data1 = jsonDecode(response1.body);

.......

String url2 = "https://api-2.php"; 
    var response2 = await http
        .get(Uri.encodeFull(url2), headers: {"Accept": "application/json"});

data2 = jsonDecode(response2.body);

.......

String url3 = "https://api-3.php"; 
    var response2 = await http
        .get(Uri.encodeFull(url3), headers: {"Accept": "application/json"});

data3 = jsonDecode(response3.body);

//*******How to add the data2 and data3 in itemCount?******//
itemCount: data1 == null ? 0 : data1.length, 

0 个答案:

没有答案