Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement continuous scroll with SingleChildScrollView and GridView in Flutter

I currently have a SingleChildScrollView as a parent and a GridView as one of the child widgets. Everything is working fine but when the GridView finishes scrolling, the scroll does not pass on to parent ScrollView. In Landscape orientation, the GridView occupies the entire screen so user gets stuck scrolling only the GridView. How can I pass the scroll?

SingleChildScrollView(
  controller: _hideButtonController,
  child: Container(
    padding: EdgeInsets.only(bottom: 80.0), //padding for fab
    child: Column(
      children: <Widget>[
        _previousWidgets(),
        _gridWidget(),
      ],
    ),
  ),
);
like image 713
Shashi Kiran Avatar asked Jul 15 '18 09:07

Shashi Kiran


People also ask

How do you make the GridView scrollable in flutter?

Add this line inside your GridView to allow scrolling physics: ScrollPhysics(), Add this line inside your GridView to disable scrolling physics: NeverScrollableScrollPhysics(), Through many examples, we learned how to resolve the Gridview Not Scrolling Flutter problem.

What is NestedScrollView flutter?

The Flutter documentation defines NestedScrollView as “A scrolling view inside of which can be nested other scrolling views, with their scroll positions being intrinsically linked.” This means that with NestedScrollView , you get two scrolling areas. One is the header part and the other is its body part.


2 Answers

Inside your GridView set physics like this and you are good to go :

physics: NeverScrollableScrollPhysics()

Edit:

Doing this can be resource intensive as it generates all the items in a single go instead of inflating/generating items on scrolling, so make sure you don't have large amount of data in your grid or list.

like image 100
Jaswant Singh Avatar answered Oct 13 '22 06:10

Jaswant Singh


You should use CustomScrollView instead of SingleChildScrollView.

CustomScrollView is a scrollview that can combine multiple type of content. Such as list, grid, or plain widget.

CustomScrollView(
  slivers: <Widget>[
    SliverToBoxAdapter(
      child: Container(
        height: 50.0,
        width: double.infinity,
        color: Colors.yellow,
      ),
    ),
    SliverGrid(
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: 2,
          childAspectRatio: 1.0,
          mainAxisSpacing: 10.0,
          crossAxisSpacing: 10.0),
      delegate: SliverChildBuilderDelegate(
        (context, index) {
          return Container(
            color: Colors.red,
          );
        },
        childCount: 10,
      ),
    ),
    SliverPadding(
      padding: const EdgeInsets.only(bottom: 80.0),
    )
  ],
),
like image 20
Rémi Rousselet Avatar answered Oct 13 '22 05:10

Rémi Rousselet