HoveringHeaderList ,支持多種header、item、separator混搭,支持按indexPath跳轉(跳轉到第x組第y個item)
已更新到XBScaffold中,有需要自取:http://www.lxweimin.com/p/726c1e94df5b
源碼:
思路:
關鍵在于確定分組header的顯示區域與ScrollView對應的offset區間。
關于實現分組header懸停效果可以看我這篇文章:
flutter實現ListView頭部懸浮,item多種高度
效果:
QQ20200919-225105.gif
IMG_BF941B622A85-1.jpeg
架構:
2020-09-19 17.19.49.png
demo:
下載源碼后拷貝到你的工程里,push到下圖指向的頁面即可
image.png
屬性說明:
HoveringHeaderList(
key: _globalKey,
///分組信息,每組有幾個item
itemCounts: List.generate(5, (index) => 5),
///header builder
sectionHeaderBuild: (ctx, section) {
return Header(
"我是段頭 $section",
color: Colors.orange,
);
},
///header高度
headerHeightForSection: (section) {
return Header.height;
},
///item builder
itemBuilder: (ctx, indexPath, height) {
if (indexPath.index % 2 == 0) {
return CellOne("我是第一種cell $indexPath", () {
_globalKey.currentState.animateToIndexPath(SectionIndexPath(2, 3),
duration: Duration(seconds: 1), curve: Curves.ease);
});
} else {
return CellTwo("我是第二種cell $indexPath", () {
_globalKey.currentState.animateToIndexPath(SectionIndexPath(3, 2),
duration: Duration(seconds: 1), curve: Curves.ease);
});
}
},
///item高度
itemHeightForIndexPath: (indexPath) {
if (indexPath.index % 2 == 0) {
return CellOne.height;
} else {
return CellTwo.height;
}
},
///分割線builder
separatorBuilder: (ctx, indexPath, height, isLast) {
// print("indexPath : $indexPath,$isLast");
return Separator();
},
///分割線高度
separatorHeightForIndexPath: (indexPath, isLast) {
return Separator.height;
},
///滾動到底部和離開底部的回調
onEndChanged: (end) {
print("end : $end");
},
///offset改變回調
offsetChanged: (offset) {
// print("111111:offset : $offset");
},
///滾動到頂部和離開頂部的回調
onTopChanged: (top) {
print("top:$top");
},
///是否需要懸停header
hover: true,
),