ListView
2020-08-08 本文已影响0人
不二客
ListView
ListView({
Key key,
Axis scrollDirection = Axis.vertical, //列表的滚动方向
bool reverse = false,
ScrollController controller,
bool primary,
ScrollPhysics physics,//
bool shrinkWrap = false,//列表的长度是否仅包裹其内容的长度 当ListView嵌在一个无限长的容器组件中时,shrinkWr
ap必须为true,否则Flutter会给出警告;
EdgeInsetsGeometry padding,//间距
this.itemExtent,//子元素长度
bool addAutomaticKeepAlives = true,//添加自动保持有效
bool addRepaintBoundaries = true,//添加重绘边界
bool addSemanticIndexes = true, //添加语义索引
double cacheExtent, // 预渲染区域长度
List<Widget> children = const <Widget>[],
int semanticChildCount,
DragStartBehavior dragStartBehavior = DragStartBehavior.start, //拖动开始行为
ScrollViewKeyboardDismissBehavior keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual, //滚动视图键盘关闭行为
})
DragStartBehavior
拖动开始行为
down 向下
start 开始
ScrollViewKeyboardDismissBehavior
滚动视图键盘关闭行为
manual 手册
onDrag 拖航
ListView.builder
childrenDelegate = SliverChildBuilderDelegate(
itemBuilder,
childCount: itemCount,
addAutomaticKeepAlives: addAutomaticKeepAlives,
addRepaintBoundaries: addRepaintBoundaries,
addSemanticIndexes: addSemanticIndexes,
)
ListView.separated
childrenDelegate = SliverChildBuilderDelegate(
(BuildContext context, int index) {
final int itemIndex = index ~/ 2;
Widget widget;
if (index.isEven) {
widget = itemBuilder(context, itemIndex);
} else {
widget = separatorBuilder(context, itemIndex);
assert(() {
if (widget == null) {
throw FlutterError('separatorBuilder cannot return null.');
}
return true;
}());
}
return widget;
},
ListView.custom
const ListView.custom({
Key key,
Axis scrollDirection = Axis.vertical,
bool reverse = false,
ScrollController controller,
bool primary,
ScrollPhysics physics,
bool shrinkWrap = false,
EdgeInsetsGeometry padding,
this.itemExtent,
@required this.childrenDelegate,
double cacheExtent,
int semanticChildCount,
}) :