gat*_*tti 9 listview dart flutter
我正在从Stream构建ListView.我需要为该列表添加删除和插入动画,但不知道如何.
我已经看过Flutter的这个示例,但它与流无关:https://flutter.io/catalog/samples/animated-list/
任何帮助非常感谢:)
new StreamBuilder(
stream: feed.stream, // this is a Stream<List<Product>>
builder: (context, snapshot) {
if (!snapshot.hasData)
return const Text('Loading products');
return new ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
Product product = snapshot.data[index];
return new ProductWidget(product);
});
});
Run Code Online (Sandbox Code Playgroud)
作为 的替代方案ListView,您可以使用AnimatedList:
// Remove "Pig" from the list
int removeIndex = 2;
// remove the item from the data list backing the AnimatedList
String removedItem = _data.removeAt(removeIndex);
// This builder is just so that the animation has something
// to work with before it disappears from view since the original
// has already been deleted.
AnimatedListRemovedItemBuilder builder = (context, animation) {
// A method to build the Card widget.
return _buildItem(removedItem, animation);
};
// notify the AnimatedList that the item was removed
_listKey.currentState.removeItem(removeIndex, builder);
Run Code Online (Sandbox Code Playgroud)
这篇文章解释了更多。这是完整的代码:
// Remove "Pig" from the list
int removeIndex = 2;
// remove the item from the data list backing the AnimatedList
String removedItem = _data.removeAt(removeIndex);
// This builder is just so that the animation has something
// to work with before it disappears from view since the original
// has already been deleted.
AnimatedListRemovedItemBuilder builder = (context, animation) {
// A method to build the Card widget.
return _buildItem(removedItem, animation);
};
// notify the AnimatedList that the item was removed
_listKey.currentState.removeItem(removeIndex, builder);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2270 次 |
| 最近记录: |