flutter:實(shí)現(xiàn)ListView頭部懸浮

最近app想要類似于ios的那種tableview,區(qū)頭懸停的效果。最后找到了一個(gè)大神的方案。比較不錯(cuò),UI效果也達(dá)到了理想效果。
具體的實(shí)現(xiàn)代碼:
主要是gsy大神的這個(gè)類:(地址:https://github.com/CarGuo/gsy_flutter_demo

stick_render.dart
stick_widget.dart

這兩個(gè)類需要下載下來(lái),放到你的項(xiàng)目中去,然后實(shí)現(xiàn)這種效果的方法就很簡(jiǎn)單了。

準(zhǔn)備好數(shù)據(jù)源:
Map<String, List<String>> itemSectionList = {
  '遠(yuǎn)程模塊': ["遠(yuǎn)程拜訪"],
  '訂單提醒模塊': ["遠(yuǎn)程訂單"],
  '拜訪提醒模塊': ["店前拜訪提醒"],
  '門店拜訪': ["1-進(jìn)入門店"],
  '生動(dòng)化執(zhí)行': ["2-生動(dòng)化執(zhí)行"],
  '店鋪檢查': ["3-店鋪檢查"],
  '庫(kù)存建議': ["4-店鋪檢查"],
  '店員教育': ["5-店員教育"],
  '結(jié)束拜訪': ["6-結(jié)束拜訪"],
  '未拜訪原因': ["7-未拜訪原因"],
};
實(shí)現(xiàn)方法:
class sectionTableview extends StatelessWidget {
  sectionTableview({super.key});
  //區(qū)頭數(shù)組
  final List _titles = itemSectionList.keys.toList();
  @override
  Widget build(BuildContext context) {
    return ListView.builder(
        physics: AlwaysScrollableScrollPhysics(),
        itemCount: itemSectionList.length,
        itemBuilder: (context, index) {
          String sectiontitle = _titles[index];
        String cellValue = itemSectionList[sectiontitle]?.first as String;
          return Container(
            height: 100.0,
            child: StickWidget(
              ///區(qū)頭header
              stickHeader: Container(
                height: 50.0,
                color: Colors.greenAccent[400],
                padding: const EdgeInsets.only(left: 10.0),
                alignment: Alignment.centerLeft,
                child: InkWell(
                  onTap: () {
                    print("header");
                    String title = _titles[index];
                    Log.i('----->$title');
                  },
                  child: Text(
                    '模塊:$sectiontitle',
                  ),
                ),
              ),
              ///content
              stickContent: InkWell(
                onTap: () {
                  print("content");
                },
                child: Container(
                  margin: const EdgeInsets.only(left: 10),
                  // color: Colors.pinkAccent,
                  height: 50.0,
                  child: Text(cellValue),
                ),
              ),
            ),
          );
        });
  }
}

需要注意的是區(qū)頭和cell的高度是固定的,而且外面的container高度也是固定的。具體的實(shí)現(xiàn)原來(lái)需要看StickRender這個(gè)類。


Untitled.gif
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容