'Prevent a NestedScrollView from scrolling
I have a widget that is a NestedScrollView and some text in the body. There are cases where I want to "lock" the user and not allow him to scroll. I have tried using the physics property and set it to NeverScrollableScrollPhysics()as the docs seem to indicate this is what it is for: https://api.flutter.dev/flutter/widgets/NeverScrollableScrollPhysics-class.html however this does not seem to be working and the screen still scrolls.
Is there a way to prevent the scroll?
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 2,
child: NestedScrollView(
physics: NeverScrollableScrollPhysics(),
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
expandedHeight: 150.0,
floating: false,
pinned: true,
forceElevated: true,
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
title: Text('I am a header'),
),
)
];
},
body: Text(' I am scrolling'),
));
}
Solution 1:[1]
There is a widget called AbsorbPointer
. Wrap it around your NestedScrollView
.
AbsorbPointer(
isAbsorbing: true,
child: NestedScrollView(...))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Kerim |