const SliverChildBuilderDelegate(
this.builder, // 创建子元素 (BuildContext context, int index){return build}
{
this.findChildIndexCallback, // 调用它,以便在重新排序时根据子元素的键查找新索引。如果没有提供,当子部件从[builder]返回的顺序发生变化时,子部件可能不会映射到它现有的[RenderObject]。这可能会导致状态损失。这个回调函数应该接受一个input [Key],它应该返回子元素的索引(如果没有找到)。
this.childCount,// 限制子孩子的个数
this.addAutomaticKeepAlives = true,
this.addRepaintBoundaries = true,
this.addSemanticIndexes = true,
this.semanticIndexCallback = _kDefaultSemanticIndexCallback,
this.semanticIndexOffset = 0,
}) : assert(builder != null),
assert(addAutomaticKeepAlives != null),
assert(addRepaintBoundaries != null),
assert(addSemanticIndexes != null),
assert(semanticIndexCallback != null);
基本用法
return CustomScrollView(
slivers: <Widget>[
SliverAppBar(
expandedHeight: 200.0,
pinned: true, // 当滑动到底部的时候则显示标题
leading: IconButton(icon: Icon(Icons.arrow_back_ios), color: Colors.red, onPressed: (){
}),
backgroundColor: Colors.black,
flexibleSpace: FlexibleSpaceBar( // 背景
title: Text('娜扎之魔童降世', style: TextStyle(
color: Color(0xffe5e5e5),
fontSize: 16,
),),
background: Image.network(
'https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3254228255,2309346508&fm=26&gp=0.jpg',
fit: BoxFit.fitHeight, // 沾满真个高度
),
),
),
// SliverList(
// delegate: SliverChildBuilderDelegate((content, index) {
// return Container(
// height: 65,
// color: Colors.primaries[index % Colors.primaries.length],
// );
// }, childCount: 5),
// )
SliverFixedExtentList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index){
return Card(
child: Container(
alignment: Alignment.center,
color: Colors.primaries[(index % 18)],
child: Text(index.toString()),
),
);
},
childCount: 7, // 如不设置则无限个子孩子
findChildIndexCallback: (key) => 0,
semanticIndexOffset: 2
),
itemExtent: 80.0)
],
);