小编dwa*_*wax的帖子

防止 NestedScrollView 滚动

我有一个小部件,它是 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)

flutter

6
推荐指数
1
解决办法
451
查看次数

标签 统计

flutter ×1