Updating data in an AnimatedList in Flutter
Published in
4 min readJun 4, 2019
Smoothly handling changes to a ListView
If you have seen the Widget of the Week video about AnimatedList
yet, now would be a good time to do so.
This article will provide specific code snippets for various ways to update an AnimatedList
. The process includes two main steps every time:
1. Update the data set
// initial data
List<String> _data = ['Horse', 'Cow', 'Camel', 'Sheep', 'Goat'];
2. Notify the AnimatedList’s global key about the change
final GlobalKey<AnimatedListState> _listKey = GlobalKey();
You can find the full code at the end of the article. Or you can play with it on DartPad.
Insert single item
Add “Pig” at index 2
.
String item = "Pig";
int insertIndex = 2;
_data.insert(insertIndex, item)…