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(),
],
),
),
);
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.
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.
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.
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),
)
],
),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With