title: Flutter: The getter 'length' was called on null
body: <p>when I'm trying call the api it gets called and it reaches the <code>itemCount</code> in the <code>ListView.builder</code> but then it shows error like this,</p>
  <blockquote>
  <p>The getter 'length' was called on null.</p>
  </blockquote>
  <pre><code>class ChopperNewsCard extends StatefulWidget {
    @override
    _ChopperNewsCardState createState() =&gt; _ChopperNewsCardState();
  }
  
  class _ChopperNewsCardState extends State&lt;ChopperNewsCard&gt; {
    ScrollController scrollController = ScrollController();
    ApiCall apiCall = ApiCall();
    ChopperNews res = ChopperNews();
    Future&lt;void&gt; getResponse() async {
      res = await apiCall.getNews(5);
    }
  
    @override
    void initState() {
      super.initState();
  
      getResponse();
    }
  
    @override
    void dispose() {
      super.dispose();
      scrollController.dispose();
    }
  
    @override
    Widget build(BuildContext context) {
      var height = MediaQuery.of(context).size.height;
      var width = MediaQuery.of(context).size.width;
      return Container(
        height: height * 0.37,
        width: double.infinity,
        child: ListView.builder(
          itemCount: res.articles.length + 1, //&lt;--------here length getting null
          controller: scrollController,
          physics: AlwaysScrollableScrollPhysics(),
          scrollDirection: Axis.horizontal,
          shrinkWrap: true,
          itemBuilder: (context, index) {
            if (index == res.articles.length) {
              if (index == res.totalResults) {
                return null;
              } else {
                return Center(child: CircularProgressIndicator());
              }
            } else {
              return Container(
                width: width * 0.70,
                padding: EdgeInsets.only(right: width * 0.05),
                child: Card(
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(15),
                  ),
                  elevation: 3,
                  child: Column(
                    children: [
                      ClipRRect(
                        borderRadius: BorderRadius.circular(15),
                        child: CachedNetworkImage(
                          imageUrl: res.articles[index].urlToImage == null
                              ? Url.noImage
                              : res.articles[index].urlToImage,
                          fit: BoxFit.cover,
                          width: double.infinity,
                          height: height * 0.2,
                          placeholder: (context, url) =&gt;
                              Center(child: CircularProgressIndicator()),
                          errorWidget: (context, url, error) =&gt;
                              Icon(Icons.error_outline_sharp),
                        ),
                      ),
                    
                    ],
                  ),
                ),
              );
            }
          },
        ),
      );
    }
  }
  </code></pre>
  <p>from where I'm trying to call my api,</p>
  <pre><code>import 'package:chopper/chopper.dart';
  import '../models/chopper_news.dart';
  
  import 'chopper_api_service.dart';
  
  class ApiCall {
    ChopperApiService chopperApiService;
    Future&lt;ChopperNews&gt; getNews(int page) async {
      chopperApiService = ChopperApiService.create();
     var apiResponse = await chopperApiService.getNews(pageSize: page);
      return apiResponse.body;
    }
  }
  </code></pre>
  <p>in debug mode it shows response after the length is getting called null so my api calls I think are working fine</p>