Ad

Flutter Nested ListView

- 1 answer

I have 2 ListViews the first one is one top of the page and shows stories so it's horizontal and the second one is Showing Posts so it's vertical.

What I want is that when I scroll my posts I want the storys to disappear right now they are stuck on top of the page.

Explanation Video this

@override
        Widget build(context) {
          return Scaffold(
          
            body: SafeArea(
              child: Column(
                children: [
                
                Container(
                    padding: EdgeInsets.only(left: 15),
                    height: 90,
                    width: double.infinity,
                    child: StreamBuilder(
                      stream: masterListStart().asStream(),
                      builder: (context, snapshot) {
                    
                          return (ConnectionState.done == snapshot.connectionState)
                              //First Listview
                              ? ListView.builder(
                                  scrollDirection: Axis.horizontal,
                                  shrinkWrap: true,
                                  itemCount: storysList.length,
                                  itemBuilder: (context, index) {
                                    //
                                    StoryItems data = storysList[index];
                                    //
                                    return StoryItems(
                                      data: data,
                                    );
                                  },
                                )
                              : CircularProgressIndicator();
                        }
                      },
                    ),
                  );

                  //Second ListView
                  Expanded(
                    child:  RefreshIndicator(
                      child: ListView(
                        children: posts,
                      ),
                      key: refreshkey,
                      onRefresh: () => refreshlist(),
                    );
                  ),
                ],
              ),
            ),
          );
        }
Ad

Answer

You can use CustomScrollView for it like this.

     CustomScrollView(
      slivers : [
      SliverToBoxAdapter(child : Container(height : listHeight, 
      child ListView(),),),
      SliverList(delegate: SliverChildBuilderDelegate((context,index){
                        return Your Item;
                      },
                      childCount: data.length
                  ),]
Ad
source: stackoverflow.com
Ad