ListView does not refresh whereas attached list does (Flutter)

Another Solution!!

Replace ListView with ListView.builder

Code:

    ListView.builder(
            itemBuilder: (ctx, item) {
              return _objectList[item];
            },
            shrinkWrap: true,
            itemCount: _objectList.length,
          ),

Output:

enter image description here


Flutter is based around immutable data. Meaning that if the reference to an object didn't change, the content didn't either.

The problem is, in your case you always send to ListView the same array, and instead mutate its content. But this leads to ListView assuming the list didn't change and therefore prevent useless render.

You can change your setState to keep that in mind :

setState(() {
  _objectList = List.from(_objectList)
    ..add(Text("foo"));
});

Tags:

Dart

Flutter