title: How to know if list view is scrollable programatically
body: <p>I am copying my question from <a href="https://stackoverflow.com/questions/11173369/how-to-check-if-a-my-listview-has-scrollable-number-of-items">here</a> as it is the same question but for flutter</p>
  <blockquote>
  <p>How do you know if your ListView has enough number of items so that it
  can scroll?</p>
  <p>For instance, If I have 5 items on my ListView all of it will be
  displayed on a single screen. But if I have 7 or more, my ListView
  begins to scroll. How do I know if my List can scroll
  programmatically?</p>
  </blockquote>
  <p>Thank you</p>
  <p>I am adding the code I tried, in which I test if the controller is attached, to be able to get the position. I couldn't get the position because the controller is not attached until you actually scroll</p>
  <pre><code>Widget build(BuildContext context) {
    _afterBuild();
    ListView.builder(
      controller: controller,
      // ...
    )    
  }
  
  Future&lt;void&gt; _afterBuild () async {
      if (controller.hasClients) {
        print(&quot;controller.hasClients&quot;);
        // here I would be able to get the position
      } else {
        print(&quot;controller.has no Clients&quot;);
      }       
    }
  </code></pre>
  <hr />
  <p>Edit: For anyone coming here: The controller was not being attached because I had a condition under which to build the ListView</p>
  <p>So I combined the comments with the accepted answer (which is actually the answer for the question) and solved it like this (with some pseudocode):</p>
  <pre><code>Widget build(BuildContext context) {
    if (not loaded results from api) {
      return Something()
    } else {
      Future(_afterBuild);
      return ListView.builder(
        controller: controller,
        // ...
      )
    }          
  }
  
  Future&lt;void&gt; _afterBuild () async {   
    if (controller.hasClients) {   
      if(controller.position.maxScrollExtent &gt; 0){
        print('it can be scrolled');
      }
    } else {
      print(&quot;controller has no client&quot;);
    }            
  }
  </code></pre>