gpt4 book ai didi

flutter - Flutter-Nosuchmethoderror调用getter 'length'为null

转载 作者:行者123 更新时间:2023-12-03 03:35:48 24 4
gpt4 key购买 nike

刷新页面时,此错误首先开始,然后起作用。

Error: The getter 'isNotEmpty' was called on null. Receiver: null Tried calling: isNotEmpty


class TreePage extends StatefulWidget {
String vp;
TreePage({this.vp});
@override
_TreePageState createState() => _TreePageState();
}


class _TreePageState extends State<TreePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.blue,
title: Text('Проверка штрафов',
style: TextStyle(color: Colors.white,),
),
centerTitle: true,
),
//new return Container(),

body: new FutureBuilder(
future: getPhoneFinal(widget.vp),

//future: codePhone(widget.code),
builder: (context, snapshot){
List data = snapshot.data;
Map shtr = getByKeySh();
Map shtrIm = getByKeyIm();
Map violQnt;
if(data.isNotEmpty){
violQnt = getViolationQnt(data);
}else{
violQnt = null;
}
if(snapshot.hasError){
print (snapshot.error);
return Text('Не удалось получить ответ от сервера',
style: TextStyle(color: Colors.red,
fontSize: 22.0)
);
}
else if(snapshot.hasData ){
return ListView.builder (
itemCount: snapshot.data.length, //length of snapshot data
itemBuilder: (BuildContext ctxt, int index) {
return Container(
child:Column(
children: <Widget>[
(index == 0)?
new Container(
child:Column(
children: <Widget>[
new Text('Подтвержденные штрафы: ${violQnt['approved_qnt']}'),
]
),


)
: new Container(),


new Container(
child: Image.asset(
'images/${shtrIm[data[index] ['VId']]}',
width: 50,
height: 50,
),
),

new Container(
child: Image.asset(
'images/${(data[index] ['ProcessStatus']==1)? 'sts-ok.png': 'sts-no.png'}',
width: 50,
height: 50,
),

),
new Container(
child: new Text(

'${(data[index] ['IsPaid']==1)? 'Да': 'нет'}',

),

),

new Container(
child: new Text(
//'Тип штрафа: ${data[index]['VDescription']}'
'Тип штрафа: ${shtr[data[index] ['VId']]}'


),
),
new Container(
child: new Text(
'Адрес: ${data[index]['VLocation']}'
),
),
new Container(
child: new Text(
'Дата: ${data[index]['VTime']}'
),
),
],
),
);
}
);
}else if(!snapshot.hasData){
return new Center(child: CircularProgressIndicator(),);
}
}),
);
}

// getFine(String vp) {}


}



Future<Map> getPhone(String phone,String code) async{
String url = 'xxx/xxx/$phone/$code';
http.Response response = await http.get(url);
//var sts = response.statusCode;
//log( response.statusCode);
// var ar = {
// 'sts': response.statusCode,
//'data': json.decode(response.body)
//};
return json.decode(response.body);
}

Future<List> getPhoneFinal(String numbCar) async{
String url = 'xxx/xxx/$numbCar';
http.Response response = await http.get(url);
return json.decode(utf8.decode(response.bodyBytes));
}



Map<String, String> getByKeySh() {
return {
'1625': 'Проезд на красный сигнал светофора',
'1302': 'Проезд на красный сигнал светофора',
'1230': 'Пересечение сплошной линии',
'1301': 'Движение по встречной полосе',
//1301 => 'Выезд на полосу встречного движения',
'1345': 'Выезд за стоп-линию'
};
}
Map<String, String> getByKeyIm() {
return {
'1625': '1625.png',
'1302': '1302.png',
'1230': '1230.png',
'1301': '1301.png',
//1301 => '',
'1345': '1345.png'
};


}

Map<String, int> getViolationQnt(List data ) {
var total_qnt = 0;
var approved_qnt = 0;
var paid_qnt = 0;
var process_qnt = 0;

// if(data.isNotEmpty){

for(var i=0; i< data.length; i++){
total_qnt++;
if(data[i]['IsPaid'] == 1){
paid_qnt++;
}
if(data[i]['IsPaid'] == 0 && data[i]['ProcessStatus'] == 1){
approved_qnt++;
}
if(data[i]['IsPaid'] == 0 && data[i]['ProcessStatus'] != 1){
process_qnt++;
}
}
// }
return {
'total_qnt': total_qnt,
'approved_qnt': approved_qnt,
'paid_qnt': paid_qnt,
'process_qnt': process_qnt,
};


}

最佳答案

请使用data.length > 0代替data.isNotEmpty()也可以使用snapshot.hasData检查

关于flutter - Flutter-Nosuchmethoderror调用getter 'length'为null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61251873/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com