title: Adding new pages to a PageView while swiping
body: <p>I am currently making a calendar app that I would like to swipe right or left to go to the next or previous month.  I am using a PageView by initially setting up an array with 3 items in it and the initial page being the second one.  I would like to swipe right and add a page to the end.  I would like to swipe left and add a page to the beginning.  Currently, if you go to the right (adding pages to the end) it works great.  But if you go to the left (adding pages to the beginning) there is some odd behavior and it doesn't work at all.  </p>
  
  <p>I have pasted a simple example below with counters.  I am not sure if I am doing it right or if my logic is off.  Can anyone let me know the correct way to do this?</p>
  
  <pre><code>import 'package:flutter/material.dart';
  
  void main() =&gt; runApp(LimeApp());
  
  class LimeApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        title: 'Pageview Test',
        home: MainPage(),
      );
    }
  }
  
  int _lowerCount = -1;
  int _upperCount = 1;
  
  class MainPage extends StatelessWidget {
    final List&lt;Widget&gt; _pages = &lt;Widget&gt;[
      new Center(child: new Text("-1", style: new TextStyle(fontSize: 60.0))),
      new Center(child: new Text("0", style: new TextStyle(fontSize: 60.0))),
      new Center(child: new Text("1", style: new TextStyle(fontSize: 60.0)))
    ];
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: Container(
          margin: EdgeInsets.symmetric(
            vertical: 50.0,
          ),
          child: PageView(
            onPageChanged: (pageId){
              if(pageId == _pages.length - 1){
                print("Last page, add page to end");
                _upperCount = _upperCount + 1;
                _pages.add(new Center(child: new Text(_upperCount.toString(), style: new TextStyle(fontSize: 60.0))));
              }
              if(pageId == 0){
                print("First page, add page to start");
                _lowerCount = _lowerCount - 1;
                _pages.insert(0, new Center(child: new Text(_lowerCount.toString(), style: new TextStyle(fontSize: 60.0))));
              }
            },
            controller: PageController(
              initialPage: 1,
            ),
            children: _pages,
          ),
        ),
      );
    }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/U79Q1.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/U79Q1.gif" alt="Swiping Example:"></a></p>