(Flutter) Infinite Scroll `ListView.builder` with Finite Content

后端 未结 2 807
情书的邮戳
情书的邮戳 2021-01-27 07:00

1. The Problem

How do I make my ListView.builder be able to scroll to empty space both to the top and to the bottom?

For example,

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-27 07:21

    If I understand it correctly, your best bet would be using a CustomScrollView with an expandable space in the SliverAppBar.

    Widget build(BuildContext context) {
      return Scaffold(
        body: CustomScrollView(
          slivers: [
             SliverAppBar(
               automaticallyImplyLeading: false, // gets rid of the back arrow
               expandedHeight: 250, // the collapsible space you want to use 
               flexibleSpace: FlexibleSpaceBar(
                 background: Container(
                   color: Colors.transparent
                 ),
               ),
             ),
             SliverList(
              delegate: SliverChildBuilderDelegate(
                (context, index) {
                  // put your widgetsList here
                },
                childCount: widgetsList.length,
              ),
            ),
          ]
        ),
      );
    }
    

提交回复
热议问题