banner
MiniKano

MiniKano

This is MiniKano's blog based on Blockchain technology. 新手,请多关照~
github

Using AnimatedList to implement adding and deleting list items.

AnimatedList is a stateful widget, and its corresponding state type is AnimatedListState.

The structure of AnimatedList is as follows:

There are two methods in the state to add and remove elements in the list:

Note that if the list is bound to a data source list, you cannot directly achieve the effect of updating the list by removing or adding elements. You also need to execute the following methods:

When adding or removing, the specified animation will be displayed.

When using insertItem and removeItem, you usually need to use a globalKey, but the globalKey needs to specify the generic type in order to call the methods to add and remove list elements:

To add an element, you only need to:

Removing an element is more complicated because you need to display the animation when the element leaves and then delete the corresponding entry in the data source:

Usually, we need to create a _buildItem method to dynamically create child elements. When executing removeItem, first create an identical child element in the callback, fade it out using animation, and finally delete the data in the data array.

Complete code#

Demo#

1-3[1].gif

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.