我有一个小部件,它是 NestedScrollView 和正文中的一些文本。在某些情况下,我想“锁定”用户并且不允许他滚动。我尝试使用物理属性并将其设置为 NeverScrollableScrollPhysics() 因为文档似乎表明这是它的用途:https ://api.flutter.dev/flutter/widgets/NeverScrollableScrollPhysics-class.html但是这没有似乎正在工作,但屏幕仍在滚动。
有没有办法防止滚动?
@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'),
));
}
Run Code Online (Sandbox Code Playgroud)
小智 -2
有一个名为 的小部件AbsorbPointer。将它包裹在你的周围NestedScrollView。
AbsorbPointer(
isAbsorbing: true,
child: NestedScrollView(...))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
451 次 |
| 最近记录: |