1

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(),
                    );
                  ),
                ],
              ),
            ),
          );
        }

4 Answers 4

2

you can put your story listview in SliverAppBar, it will hide your story list when you scroll up. here's the link https://flutter.dev/docs/cookbook/lists/floating-app-bar

Sign up to request clarification or add additional context in comments.

Comments

1

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
                  ),]

Comments

1

You can add on top of Column SingleChildScrollView to load the entire attribute .

Then you can stop the scroll in the second ListView with this code:

ListView(
    physics: NeverScrollableScrollPhysics(),
    shrinkWrap: true, // Edit new line

    .
    .
        ),

In this case, you will have one vertical scroll that follows SingleChildScrollView and the page is completely animated.

1 Comment

Hello thanks for the answer, I did this but I get this error RenderBox was not laid out: RenderRepaintBoundary#5dc0c relayoutBoundary=up2 NEEDS-PAINT 'package:flutter/src/rendering/box.dart': Failed assertion: line 1785 pos 12: 'hasSize' I also tried to give it a static height to solve this but the error still appears any ideas?
0

Use singlchildscrollview as a parent widget instead of a column see the example

body: SingleChildScrollView(
    child: Column(
    mainAxisSize: MainAxisSize.min,
    children: <Widget>[
      Text(
        'Headline',
        style: TextStyle(fontSize: 18),
      ),
      SizedBox(
        height: 200.0,
        child: ListView.builder(
          physics: ClampingScrollPhysics(),
          shrinkWrap: true,
          scrollDirection: Axis.horizontal,
          itemCount: 15,
          itemBuilder: (BuildContext context, int index) => Card(
                child: Center(child: Text('Dummy Card Text')),
              ),
        ),
      ),
      Text(
        'Demo Headline 2',
        style: TextStyle(fontSize: 18),
      ),
      Card(
        child: ListTile(title: Text('Motivation $int'), subtitle: Text('this is a description of the motivation')),
      ),
      Card(
        child: ListTile(title: Text('Motivation $int'), subtitle: Text('this is a description of the motivation')),
      ),
      Card(
        child: ListTile(title: Text('Motivation $int'), subtitle: Text('this is a description of the motivation')),
      ),
      Card(
        child: ListTile(title: Text('Motivation $int'), subtitle: Text('this is a description of the motivation')),
      ),
      Card(
        child: ListTile(title: Text('Motivation $int'), subtitle: Text('this is a description of the motivation')),
      ),
    ],
  ),
)`

2 Comments

Thanks for the answer I get the following error when I do this:RenderBox was not laid out: RenderRepaintBoundary#30415 relayoutBoundary=up1 NEEDS-PAINT 'package:flutter/src/rendering/box.dart': Failed assertion: line 1785 pos 12: 'hasSize' The relevant error-causing widget was Scaffold-[LabeledGlobalKey<ScaffoldState>#c7cd1] Any idea?
its a problem of height set a static height for both listview by calculating height by media query Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.