title: Flutter : PageController.page cannot be accessed before a PageView is built with it
body: <p>How to solve the exception - </p>
  
  <p>Unhandled Exception: 'package:flutter/src/widgets/page_view.dart': Failed assertion: line 179 pos 7: 'positions.isNotEmpty': PageController.page cannot be accessed before a PageView is built with it.</p>
  
  <p>Note:- I used it in two screens and when I switch between screen it shows the above exception.</p>
  
  <pre><code>@override
    void initState() {
      super.initState();
        WidgetsBinding.instance.addPostFrameCallback((_) =&gt; _animateSlider());
    }
  
    void _animateSlider() {
      Future.delayed(Duration(seconds: 2)).then(
        (_) {
          int nextPage = _controller.page.round() + 1;
  
          if (nextPage == widget.slide.length) {
            nextPage = 0;
          }
  
          _controller
              .animateToPage(nextPage,
                  duration: Duration(milliseconds: 300), curve: Curves.linear)
              .then(
                (_) =&gt; _animateSlider(),
              );
        },
      );
    }
  </code></pre>