Flutter 中 RecyclerView 的替代品是什么?
What is the alternative to RecyclerView in Flutter?
Flutter 中回收视图的替代方法是什么我尝试使用此代码
但是如何在 flutter
中使用列表视图小部件进行动画处理
这有效吗?
ListView(
children: <Widget>[
ListTile(
leading: Icon(Icons.map),
title: Text('Map'),
),
ListTile(
leading: Icon(Icons.photo_album),
title: Text('Album'),
),
ListTile(
leading: Icon(Icons.phone),
title: Text('Phone'),
),
],
);
您还可以使用 animatedlist 小部件制作动画。代码示例如下link.
ListView
:
通常这应该与少量子项一起使用,因为列表也会构造列表中的不可见元素,大量元素可能会导致效率低下。
ListView.builder()
:
列表项是惰性构建的,这意味着只构建特定数量的列表项,当用户向前滚动时,较早的列表项将被销毁。
更多信息是 here。
The recommended, efficient, and effective way to build a list uses a
ListView.Builder. This method is great when you have a dynamic List or
a List with very large amounts of data. This is essentially the
equivalent of RecyclerView on Android, which automatically recycles
list elements for you:
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Sample App"),
),
body: ListView.builder(
itemCount: widgets.length,
itemBuilder: (BuildContext context, int position) {
return getRow(position);
}));
}
Widget getRow(int i) {
return GestureDetector(
child: Padding(
padding: EdgeInsets.all(10.0),
child: Text("Row $i")),
onTap: () {
setState(() {
widgets.add(getRow(widgets.length + 1));
print('row $i');
});
},
);
}
Flutter 中回收视图的替代方法是什么我尝试使用此代码 但是如何在 flutter
中使用列表视图小部件进行动画处理这有效吗?
ListView(
children: <Widget>[
ListTile(
leading: Icon(Icons.map),
title: Text('Map'),
),
ListTile(
leading: Icon(Icons.photo_album),
title: Text('Album'),
),
ListTile(
leading: Icon(Icons.phone),
title: Text('Phone'),
),
],
);
您还可以使用 animatedlist 小部件制作动画。代码示例如下link.
ListView
:
通常这应该与少量子项一起使用,因为列表也会构造列表中的不可见元素,大量元素可能会导致效率低下。
ListView.builder()
:
列表项是惰性构建的,这意味着只构建特定数量的列表项,当用户向前滚动时,较早的列表项将被销毁。
更多信息是 here。
The recommended, efficient, and effective way to build a list uses a ListView.Builder. This method is great when you have a dynamic List or a List with very large amounts of data. This is essentially the equivalent of RecyclerView on Android, which automatically recycles list elements for you:
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Sample App"),
),
body: ListView.builder(
itemCount: widgets.length,
itemBuilder: (BuildContext context, int position) {
return getRow(position);
}));
}
Widget getRow(int i) {
return GestureDetector(
child: Padding(
padding: EdgeInsets.all(10.0),
child: Text("Row $i")),
onTap: () {
setState(() {
widgets.add(getRow(widgets.length + 1));
print('row $i');
});
},
);
}