title: Flutter - Nosuchmethoderror the getter 'length' was called on null
body: <p>When you refresh the page, this error starts first, then it works.</p>
  
  <blockquote>
    <p>Error: The getter 'isNotEmpty' was called on null.
    Receiver: null
    Tried calling: isNotEmpty</p>
  </blockquote>
  
  <pre><code>class TreePage extends StatefulWidget {
    String vp;
    TreePage({this.vp});
    @override
    _TreePageState createState() =&gt; _TreePageState();
  }
  
  
  class _TreePageState extends State&lt;TreePage&gt; {
    @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: &lt;Widget&gt;[  
                        (index == 0)?
                          new Container(
                            child:Column(
                          children: &lt;Widget&gt;[ 
                            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&lt;Map&gt; 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&lt;List&gt; getPhoneFinal(String numbCar) async{
    String url = 'xxx/xxx/$numbCar';
    http.Response response = await http.get(url);
    return json.decode(utf8.decode(response.bodyBytes));
  }
  
  
  
  Map&lt;String, String&gt; getByKeySh() {
    return {
              '1625': 'Проезд на красный сигнал светофора',
              '1302': 'Проезд на красный сигнал светофора',
              '1230': 'Пересечение сплошной линии',
              '1301': 'Движение по встречной полосе',
              //1301 =&gt; 'Выезд на полосу встречного движения',
              '1345': 'Выезд за стоп-линию'
    };
  }
    Map&lt;String, String&gt; getByKeyIm() {
    return {
              '1625': '1625.png',
              '1302': '1302.png',
              '1230': '1230.png',
              '1301': '1301.png',
              //1301 =&gt; '',
              '1345': '1345.png'
    };
  
  
  }
  
  Map&lt;String, int&gt; 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&lt; data.length; i++){
        total_qnt++;
        if(data[i]['IsPaid'] == 1){
          paid_qnt++;
        }
        if(data[i]['IsPaid'] == 0 &amp;&amp; data[i]['ProcessStatus'] == 1){
          approved_qnt++;
        }
        if(data[i]['IsPaid'] == 0 &amp;&amp; data[i]['ProcessStatus'] != 1){
          process_qnt++;
        }
      }
   // }
    return {
              'total_qnt': total_qnt,
              'approved_qnt': approved_qnt,
              'paid_qnt': paid_qnt,
              'process_qnt': process_qnt,
    };
  
  
  }
  </code></pre>