title: Flutter - Error updating a list in ListView
body: <p>I'm trying to update a list in <code>ListView</code> only when I go to the last elements of the list and do the update, either adding an item, removing it, going to another Page and returning, the list gets incomplete not showing the first items in the list.</p>
  
  <p>Below is a code in which it shows that after updating the list it was incomplete</p>
  
  <p><a href="https://i.stack.imgur.com/jU1X1.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jU1X1.gif" alt="enter image description here"></a></p>
  
  <pre><code>import 'package:flutter/material.dart';
  import 'dart:ui' as ui;
  
  void main() {
    runApp(new MyApp());
  }
  
  class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return new MaterialApp(
        home: new CategoriaPage(),
      );
    }
  }
  
  class CategoriaPage extends StatefulWidget {
    @override
    CategoriaPageState createState() =&gt; new CategoriaPageState();
  }
  
  class CategoriaPageState extends State&lt;CategoriaPage&gt;{
    Color azulAppbar = new Color(0xFF26C6DA);
    List&lt;Widget&gt; listCategories = [];
    List listaDB = [];
  
    @override
    void initState() {
      setState(() {
        this.listaDB = 
          [
            [{'category': 'foo01', 'id': 1}],
            [{'category': 'foo02', 'id': 2}],
            [{'category': 'foo03', 'id': 3}],
            [{'category': 'foo04', 'id': 4}],
            [{'category': 'foo05', 'id': 5}],
            [{'category': 'foo06', 'id': 6}],
            [{'category': 'foo07', 'id': 7}],
            [{'category': 'foo08', 'id': 8}],
            [{'category': 'foo09', 'id': 9}],
            [{'category': 'foo10', 'id': 10}],
            [{'category': 'foo11', 'id': 11}],
            [{'category': 'foo12', 'id': 12}],
            [{'category': 'foo13', 'id': 13}],
            [{'category': 'foo14', 'id': 14}],
            [{'category': 'foo15', 'id': 15}],
            [{'category': 'foo16', 'id': 16}],
            [{'category': 'foo17', 'id': 17}],
            [{'category': 'foo18', 'id': 18}],
            [{'category': 'foo19', 'id': 19}],
            [{'category': 'foo20', 'id': 20}],
            [{'category': 'foo21', 'id': 21}],
            [{'category': 'foo22', 'id': 22}],
            [{'category': 'foo23', 'id': 23}],
            [{'category': 'foo24', 'id': 24}]
          ];
      });
    }
  
    @override
    Widget build(BuildContext context) {
  
      List&lt;Widget&gt; buildListCategories(List list) {
        this.listCategories = [];
  
        for(var i in list) {
          var id = i[0]['id'];
          var category = i[0]['category'];
  
          this.listCategories.add(
            new ItemCategory(
              key: new ObjectKey(i[0]),
              id: id,
              category: category,
              onPressed: () async {
                setState(() {
                  this.listaDB = 
                  [
                    [{'category': 'foo01', 'id': 1}],
                    [{'category': 'foo02', 'id': 2}],
                    [{'category': 'foo03', 'id': 3}],
                    [{'category': 'foo04', 'id': 4}],
                    [{'category': 'foo05', 'id': 5}],
                    [{'category': 'foo06', 'id': 6}],
                    [{'category': 'foo07', 'id': 7}],
                    [{'category': 'foo08', 'id': 8}],
                    [{'category': 'foo09', 'id': 9}],
                    [{'category': 'foo10', 'id': 10}],
                    [{'category': 'foo11', 'id': 11}],
                    [{'category': 'foo12', 'id': 12}],
                    [{'category': 'foo13', 'id': 13}],
                    [{'category': 'foo14', 'id': 14}],
                    [{'category': 'foo15', 'id': 15}],
                    [{'category': 'foo16', 'id': 16}],
                    [{'category': 'foo17', 'id': 17}],
                    [{'category': 'foo18', 'id': 18}],
                    [{'category': 'foo19', 'id': 19}],
                    [{'category': 'foo20', 'id': 20}],
                    [{'category': 'foo22', 'id': 22}],
                    [{'category': 'foo23', 'id': 23}],
                    [{'category': 'foo24', 'id': 24}]
                  ];
                });
              }
            )
          );  
        }
        return this.listCategories;
      }
  
      return new Scaffold( 
        appBar: new AppBar(
          title: new Text('Categorias'),
          backgroundColor: azulAppbar,
        ),
        body: new ListView(
          padding: new EdgeInsets.only(top: 8.0, right: 0.0, left: 0.0),
          children: buildListCategories(this.listaDB)
        )
      );
    }
  }
  
  class ItemCategory extends StatefulWidget {
  
    final int id;
    final String category;
    final VoidCallback onPressed;
  
    ItemCategory({
      Key key,
      this.id,
      this.category,
      this.onPressed}) : super(key: key);
  
    @override
    ItemCategoryState createState() =&gt; new ItemCategoryState();
  }
  
  class ItemCategoryState extends State&lt;ItemCategory&gt; with TickerProviderStateMixin {
    ItemCategoryState();
  
    AnimationController _controller;
    Animation&lt;double&gt; _animation;
    double flingOpening;
    bool startFling = true;
  
    void initState() {
      super.initState();
      _controller = new AnimationController(duration: 
        const Duration(milliseconds: 246), vsync: this);
  
      _animation = new CurvedAnimation(
        parent: _controller,
        curve: new Interval(0.0, 1.0, curve: Curves.linear),
      );
    }
  
    void _move(DragUpdateDetails details) {
      final double delta = details.primaryDelta / 304;
      _controller.value -= delta;
    }
  
    void _settle(DragEndDetails details) {
      if(this.startFling) {
        _controller.fling(velocity: 1.0);
        this.startFling = false;
      } else if(!this.startFling){
        _controller.fling(velocity: -1.0);
        this.startFling = true;
      }
    }
  
    @override
    Widget build(BuildContext context) {
      final ui.Size logicalSize = MediaQuery.of(context).size;
      final double _width = logicalSize.width;
      this.flingOpening = -(48.0/_width);
  
      return new GestureDetector(
        onHorizontalDragUpdate: _move,
        onHorizontalDragEnd: _settle,
        child: new Stack(
          children: &lt;Widget&gt;[
            new Positioned.fill(
              child: new Row(
                mainAxisAlignment: MainAxisAlignment.end,
                children: &lt;Widget&gt;[
                  new Container(
                    decoration: new BoxDecoration(
                      color: new Color(0xFFE57373),
                    ),
                    child: new IconButton(
                      icon: new Icon(Icons.delete),
                      color: new Color(0xFFFFFFFF),
                      onPressed: widget.onPressed
                    )
                  ),
                ],
              ),
            ),
            new SlideTransition(
              position: new Tween&lt;Offset&gt;(
                begin:  Offset.zero,
                end: new Offset(this.flingOpening, 0.0),
              ).animate(_animation),
              child: new Container(
                decoration: new BoxDecoration(
                  border: new Border(
                    top: new BorderSide(style: BorderStyle.solid, color: Colors.black26),
                  ),
                  color: new Color(0xFFFFFFFF),
                ),
                margin: new EdgeInsets.only(top: 0.0, bottom: 0.0),
                child: new Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: &lt;Widget&gt;[
                    new Expanded(
                      child: new Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: &lt;Widget&gt;[
                          new Container(
                            margin: new EdgeInsets.only(left: 16.0),
                            padding: new EdgeInsets.only(right: 40.0, top: 4.5, bottom: 4.5),
                            child: new Row(
                              children: &lt;Widget&gt;[
                                new Container(
                                  margin: new EdgeInsets.only(right: 16.0),
                                  child: new Icon(
                                    Icons.brightness_1,
                                    color: Colors.black,
                                    size: 35.0,
                                  ),
                                ),
                                new Text(widget.category),
                              ],
                            )
                          )
                        ],
                      ),
                    )
                  ],
                ),
              )
            ),
          ],
        )
      );
    }
  }
  </code></pre>